đź“—
Everyday Cheat Sheets
  • README
  • Build
    • Architecture
      • API Management
        • Kong
      • Authentication
        • Keycloak
        • Okta
      • Cloud Native
      • Design Patterns
      • Design Principles
      • IaC
      • IoT
      • Message Broker
      • Methods
      • Networking
      • Payment
        • Stripe
      • Testing
    • Code lifecycle (ALM)
      • Automation Pipelines
        • Argo CD
        • CircleCI
        • Flux
        • Keptn
        • Travis
      • Azure DevOps
        • Azure Pipelines
      • Chef
      • GitHub
        • GitHub Actions
      • Nexus
      • Promyze
      • RunDeck
      • SaltStack
      • Sonar
      • Tuleap
    • Containers & Cloud Native
      • Argo Workflows
      • Containerization
        • Docker
          • Docker CLI
        • containerd
        • cri-o
      • CNAB
      • Dapr
      • Envoy
      • Fluentd
      • Knative
      • Kubernetes
        • Cluster API
        • etcd
        • Helm
        • k3d
        • kind
        • Kubectl
        • MetalLB
        • Minikube
      • Open Application Model (OAM)
      • Unleash
    • Data storage
      • MySQL
      • MongoDB
        • Atlas
        • Compass
        • Evergreen
        • MongoDB 4.2
        • MongoDB 5.0
        • MongoDB design
        • MongoDB events
        • MongoDB driver for .NET
        • Ops Manager
        • Realm
      • Oracle
      • Redis
      • SQL Server
      • PostgreSQL
    • Frameworks & libraries
      • Angular
        • Angular CLI
        • Angular events
      • .NET
        • ASP.NET Core
        • Blazor
        • .NET 5.0
        • .NET 6.0
        • .NET CLI
        • .NET Core
        • .NET Events
        • .NET Logging
        • .NET Testing
        • NuGet
        • WPF
        • Xamarin
      • gRPC
      • Ionic
      • Jekyll
      • Node.js
        • Express
        • NPM
      • React
        • React Native
      • Redux
    • IDE
      • Visual Studio 2022
    • Languages
      • C#
        • C# 8.0
      • ECMAScript
      • GraphQL
      • JavaScript
        • webpack
        • Yarn
      • MS-DOS
      • PHP
      • PowerShell
      • Python
      • Swagger
      • TypeScript
    • Messaging
      • Azure Service Bus
      • RabbitMQ
    • Testing
    • Workstation
      • QGIS
      • Visual Studio 2019
      • Windows 10
      • Windows Subsystem for Linux
  • Collaborate
    • Marp
    • Microsoft 365
      • Microsoft Graph
      • SharePoint Framework
        • Fluent UI
        • SharePoint Framework UI components
  • Run
    • Cloud computing
      • Alibaba
      • AWS
      • Azure
        • Azure AD
        • Azure CLI
        • Azure Container Registry
        • Azure Portal
        • Azure Service Bus
      • Firebase
      • OVH
    • Hardware
      • Single-board computers
        • Odroid
        • Raspberry Pi
    • Infrastructure automation
      • Azure Resource Manager
      • Packer
      • Pulumi
      • Puppet
      • Terraform
        • HCL
        • Terraform CLI
        • Terraform Providers
    • Networking
      • HAProxy
      • nginx
    • Observability
      • Grafana Labs
        • Grafana
        • Loki
        • Tempo
      • OpenTelemetry
      • Prometheus
      • Splunk
    • Security
      • Falco
    • Systems
      • Linux
        • CentOS
        • eBPF
        • Linux Kernel
        • Rocky
        • Ubuntu
      • Windows Server
    • Virtualization
      • Hyper-V
      • Vagrant
  • Optimize
    • DevOps
  • Join
    • Companies
      • HashiCorp
Powered by GitBook
On this page
  • Learn
  • Official resources
  • Key features
  • Products
  • Getting further
  • Recipes
  • Releases
  • First steps
  • MongoDB Shell
  • Local Server
  • Docker
  • Server
  • Start with Docker
  • Start from the command line
  • Client
  • Command line
  • MongoDB Shell (mongosh)
  • Sample data
  • Open source tools
  • Deployment typologies
  • MongoDB & OVH

Was this helpful?

Export as PDF
  1. Build
  2. Data storage

MongoDB

PreviousMySQLNextAtlas

Last updated 1 year ago

Was this helpful?

MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era.

→ , ,

Learn

Official resources

  • : presentations, webinars, white papers

Key features

  • Flexible schema

  • Performance

  • High Availability

    • Primary / Secondaries architecture

  • BSON storage (Binary JSON)

    • support of for encoding a variety of geographic data structures

  • ACID transactions

  • Sharding

Replication

A replica set is a group of mongod processes that maintain the same data set. Replica sets provide redundancy and high availability.

A node of the replica set can be: Primary, Secondary, Arbitrer.

Read preference

Write concern

Read concern

Indexing

Indexes gets have better read time but have an impact on write time.

Index Types:

  • Single Field

  • Compound Index

  • Multikey Index

  • Geospatial Index

  • Text Indexes

  • Hashed Indexes

Index Properties:

  • Unique Indexes

  • Partial Indexes

  • Sparse Indexes

  • TTL Indexes (Time To Live)

Performance

Storage engine

The storage engine that is used can be seen with the command db.serverStatus(). It is a mongod option: --storageEngine.

In March 2015, there were two choices: MMAPv1 (original) and WiredTiger (new).

Wired Tiger is new in MongoDB 3.0. It is the first pluggable storage engine.

Features:

  • Document level locking

  • Compression

    • Snappy (default) - fast

    • Zlib - more compression

    • None

  • Lacks some pitfalls of MMAPv1

  • Performance gains

Background:

  • Built separately from MongoDB

  • Used by other's DB

  • Open source

Internals:

  • Stores data in btrees

  • Writes are initially separate, incorporated later

  • Two caches

    • WT caches - 1/2 of RAM (default)

    • FS cache

  • Checkpoint: every minute or more

  • No need for a journal

Transactions

High availability

Data types

Products

Getting further

Recipes

Releases

Version
Date
More

4.4

June 09, 2020

First steps

MongoDB Shell

MongoDB Shell on Windows

  • You'll download a file like mongodb-win32-x86_64-2008plus-ssl-4.0.4.zip

  • Unzip the content of the archive in a program folder (for example D:\Programs folder)

  • Rename the folder with something explicit like mongodb-community-4.0.4

  • You can either update your PATH globally on your machine or do it when you need it (or through a bat file)

    SET PATH=%PATH%;D:\Programs\mongodb-community-4.0.4\bin

First commands

  • The following command must return a valid output

    mongo --version

    MongoDB shell version v4.0.4 git version: f288a3bdf201007f3693c58e140056adf8b04839 allocator: tcmalloc modules: none build environment: distmod: 2008plus-ssl distarch: x86_64 target_arch: x86_64

Local Server

  • If you followed the steps to have the Mongo Shell, you'll be able to launch easily a MongoDB server locally (mongod).

    # make sure the data path exists
    md /path/to/data
    # start a basic MongoDB instance (default port 27017)
    mongod --dbpath=/path/to/data
  • You can then connect with the MongoDB Shell:

    mongo

Docker

  • Check the images already downloaded locally

    docker images
  • Get the image for a specific version of MongoDB

    docker image pull mongo:4.0.4
  • Start the container

    docker run -d -p 27017:27017 --name mongodb404 mongo:4.0.4

Server

Start with Docker

docker run --name mongodb -d -p 27017:27017 mongo:4.4.6

Start from the command line

mongod --dbpath "C:\my\path" --port 27017

Client

Command line

# start a mongo shell and be on mycollection
mongo --port 27017 mycollection

# restore from dump folder into mydbname database
mongorestore -d mydbname dump

# monitor basic usage statistics for each collection
mongotop

# monitor basic MongoDB server statistics
mongostat

MongoDB Shell (mongosh)

Introduced in June 2020, avalable as a standalone package, it provides a fully functional JavaScript/Node.js environment for interacting with MongoDB deployments. It can be used to test queries and operations directly with one database.

mongosh <connection_string>

Sample data

Zip code

  • Import the data into your MongoDB server

    # to be run in the folder containing the json file
    mongoimport --db demoZip --collection zips --file zips.json
    # it should generate the following output
    # 2018-11-19T14:48:53.296+0100    connected to: localhost
    # 2018-11-19T14:48:53.705+0100    imported 29353 documents
  • You can also import the data to your Atlas cluster

    mongoimport --uri "mongodb+srv://user:password@mycluster.mongodb.net/demoZip" --collection zips --file zips.json

dbKoda samples

Open source tools

mtools

mtools is a collection of helper scripts to parse, filter, and visualize MongoDB log files (mongod, mongos). mtools also includes mlaunch, a utility to quickly set up complex MongoDB test environments on a local machine.

You'll need Python (2 or 3) to install and use it.

# install with pip (Python)
pip install mtools

Deployment typologies

MongoDB & OVH

MongoDB indexes use a data structure.

See also - February 12, 2020

Store large data:

,

Go to the , select "Server", then "MongoDB Community Server" edition, chose the target platform and version and let the download complete.

→

→ , , ,

Download the zip file export from .

dbKoda holds a collection of sample data: .

More information on , .

- May 28, 2021

mongodb.com
Github
developer.mongodb.com
Documentation
Resources
MongoDB University
Engineering Journal
SlideShare
Videos
GeoJSON Objects
GeoJson format
The cost of MongoDB ACID transactions in theory and practice
Database Sharding: Concepts and Examples
Manual
Manual
Manual
Manual
Manual
Query Plans
Limits
Analyze Query Performance
B-tree
Performance Best Practices: Indexing
Manual
Presentation
Documentation
MongoDB and Jepsen
jepsen.io
jepsen-io/jepsen
wikipedia Raft
Raft - The Understandable Distributed Protocol
Quick Start: BSON Data Types - ObjectId
Atlas
Compass
Ops Manager
Events
News
GridFS
mongofiles
Building MongoDB Applications with Binary Files Using GridFS
download center
docs.mongodb.com/program/mongo
Documentation
Download
GitHub
Introduction
docs.mongodb.com/manual/tutorial/aggregation-zip-code-data-set
github.com/SouthbankSoftware/dbkoda-data
github.com/rueckstiess/mtools
mongodb.com/blog/post/introducing-mtools
FR - OVHcloud et MongoDB s’allient pour proposer une solution facilitant l’innovation des données dans le cloud
5.0
Annoucement
Paper
4.2