Skip to content

MongoDB

May 28, 2026
December 17, 2014

MongoDB after 3.6 uses SSPL

ferretdb

MongoDB: The World’s Leading Modern Database | MongoDB
MongoDB Evolved – Version History | MongoDB
MongoDB 8.0 Is Available Now | MongoDB
MongoDB 6.0 Brings Encrypted Queries, Time-Series Data Collection – The New Stack

Manual Reference - Database Manual - MongoDB Docs
What is MongoDB? - Database Manual - MongoDB Docs
MongoDB - Back to Basics - YouTube
MongoDB Tutorial for Beginners - YouTube

MongoDB Courses and Trainings | MongoDB University
Level Up Your MongoDB Skills
How To Manage Data with MongoDB | DigitalOcean

karlseguin/the-little-mongodb-book: The Little MongoDB Book 2.6
Stock Price Notifications with Mongoose and MongoDB Change Streams | www.thecodebarbarian.com 2018

Percona Server for MongoDB

Percona Software for MongoDB - Best MongoDB Server Alternative

mongod server

mongod - Database Manual - MongoDB Docs
Authentication on Self-Managed Deployments - Database Manual - MongoDB Docs
DO add authSource to mongourl: mongodb://${MONGO_ROOT}:${MONGO_PASSWORD}$@127.0.0.1:27017/${COLLECTION}?authSource=admin
Role-Based Access Control in Self-Managed Deployments - Database Manual - MongoDB Docs

Booting a mongoDB container with user specified credentials | Lakshmi Narasimhan

docker-library/mongo: Docker Official Image packaging for MongoDB
docs/README.md at master · docker-library/docs

docker-entrypoint-initdb.d, mongo client script
docs/mongo at master · docker-library/docs · GitHub
Initializing mongo db in docker-compose with init script · GitHub

mongosh client

Welcome to MongoDB Shell (mongosh) - mongosh - MongoDB Docs
mongosh Methods - Database Manual - MongoDB Docs
Geospatial Queries - Database Manual - MongoDB Docs

mongodb-labs/mongosh-snippets: An experimental plugin feature for mongosh

mongodump/mongorestore

mongodump - Database Tools - MongoDB Docs
mongorestore - Database Tools - MongoDB Docs

mongodump --archive="mongodump-test-db" --db=test
# with database name change
mongorestore --archive="mongodump-test-db" --nsFrom='test.*' --nsTo='examples.*'

mongoexport/mongoimport

mongoexport - Database Tools - MongoDB Docs
mongoimport - Database Tools - MongoDB Docs

mongoexport --db test --collection traffic --out traffic.json
mongoexport --db users --collection contacts --type=csv --fields name,address --out /opt/backups/contacts.csv
# fieldFile can be used for CSV
mongoimport --db test --collection traffic traffic.json
# the CSV has header line
mongoexport --db users --collection contacts --type=csv --headerline contacts.csv

Admin UI

mongo-express - Docker Hub
mongo-express/mongo-express: Web-based MongoDB admin interface, written with Node.js and express
Too fast, too insecure: Securing Mongo Express web administrative interfaces - Help Net Security

On the contrary

Why You Should Never Use MongoDB « Sarah Mei
Why you should never, ever, ever use MongoDB - joepie91's Ramblings
MongoDB queries don’t always return all matching documents! — Meteor Engineering

#perfmatters

Performance Best Practices: Hardware and OS Configuration | MongoDB 2020
Simple Steps to Optimize Your App Performance with MongoDB, Redis, and Node.js - By 2018

MongoDB Performance - Database Manual - MongoDB Docs
Comparing MongoDB performance on public clouds: AWS, Azure & DigitalOcean

Explain Results - Database Manual - MongoDB Docs
Interpret Explain Plan Results - Database Manual - MongoDB Docs
Query Plans - Database Manual - MongoDB Docs
Getting started with MongoDB explain() | by Guy Harrison | MongoDB Performance Tuning | Medium

Internals

MongoDB internal Architecture. I’m a big believer that database… | by Hussein Nasser | Medium
MongoDB Internal Architecture - YouTube âť—!important

2x Faster Reads and Writes with this MongoDB feature | Clustered Collections - YouTube
Clustered Collections — MongoDB Manual

Previously, a find by _id is two index search, one in _id index for the recordId, one in the internal recordId index for the actual BSON document
Clustered Collections in 5.3 merged the two index and _id index's leaves are the BSON documents

Indexes

Indexing Strategies - Database Manual - MongoDB Docs
How To Use Indexes in MongoDB | DigitalOcean

Indexes - Database Manual - MongoDB Docs
Compound Indexes - Database Manual - MongoDB Docs
Multikey Indexes - Database Manual - MongoDB Docs for arrays in documents
Hashed Indexes - Database Manual - MongoDB Docswhen index field > 1024 bytes
db.collection.createIndex() (mongosh method) - Database Manual - MongoDB Docs

[SERVER-3294] Ability to keep data on disk in ~ index order - MongoDB Jira WiredTiger does not implement (and cannot guarantee) index clustering on disk level

Create a text index, the use collection.find( { $text: { $search: value } } )

Text Search on Self-Managed Deployments - Database Manual - MongoDB Docs
How To Perform Full-text Search in MongoDB | DigitalOcean

mongodb - Text search query for text "other" always returns no results? - Stack Overflow stemmed word match, non-language words must be exact match

stop words are by default skipped, use {"language": "none"} when creating index to override this behavior
mongo/src/mongo/db/fts at v4.4 · mongodb/mongo · GitHub

$regex - Database Manual - MongoDB Docs
db.collection.find( { field: { $regex: query, $options: "i" } } )

TTL (Auto Expiry)

Create index on a date field with expireAfterSeconds option

db.collection.createIndex({ createdAt: 1 }, { expireAfterSeconds: 60 }); // auto field (Mongoose)
db.collection.createIndex({ expireAt: 1 }, { expireAfterSeconds: 0 }); // manual field

Using manual field you can change the expire period without recreating the index.

TTL Indexes - Database Manual - MongoDB Docs
Expire Data from Collections by Setting TTL - Database Manual - MongoDB Docs
How to Erase Expired Docs Automatically with MongoDB (TTL index) | Hacker Noon
MongoDB Auto Expire Documents - DEV Community

Sessions API/transactions

Since 3.6, provides causal consistency, multi-document transactions

MongoDB’s ACID Transaction Guarantee | MongoDB
Transactions - Database Manual - MongoDB Docs
Session - Database Manual - MongoDB Docs

A Node.js Perspective on MongoDB 4.0: Transactions | www.thecodebarbarian.com

Mongoose: Transactions

Schema Validation

Since 3.6

Schema Validation - Database Manual - MongoDB Docs
$jsonSchema - Database Manual - MongoDB Docs
How To Use Schema Validation in MongoDB | DigitalOcean

serialization#JSON schema

Showing validation rules:

db.getCollectionInfos({ name: "myCollection" });

Mongoose

Mongoose ODM client side ORM and validation
Introduction to Mongoose for MongoDB

Mongoose Schemas
Mongoose: Schema schema method, pre/post hooks
Mongoose: Model
Mongoose: Document

yoitsro/joigoose: Joi validation for your Mongoose models without the hassle of maintaining two schemas Joi -> Mongoose

const joigoose = require("joigoose")(mongoose);

const mongooseSchema = new mongoose.Schema(joigoose.convert(joiSchema));
mongose.model("Model", mongooseSchema);

Search Results | Snyk JSON Schema -> Mongoose
convert-json-schema-to-mongoose - npm package | Snyk
@simplyhexagonal/json-schema-to-mongoose-schema - npm package | Snyk

node.js - MongoDB: output 'id' instead of '_id' - Stack Overflow

What is the difference between Mongoose toObject and toJSON? - Stack Overflow
Documentation: clarify the difference between toObject() and toJSON() · Issue #2072 · Automattic/mongoose
Mongoose toObject and toJSON transform behavior with sub-documents | Alexander Zeitler

Python

mongodb/motor: Motor - the async Python driver for MongoDB and Tornado or asyncio
art049/odmantic: Async ODM (Object Document Mapper) for MongoDB based on python type hints
BeanieODM/beanie: Asynchronous Python ODM for MongoDB

Scaling

Replication - Database Manual - MongoDB Docs
Sharding - Database Manual - MongoDB Docs

MongoDB is web scale
Indexing, Replicating, and Sharding in MongoDB [Tutorial] | Packt Hub
Configuring a MongoDB Replica Set for Analytics - DZone Database

Data Modeling

Data Modeling in MongoDB - Database Manual - MongoDB Docs
Database References - Database Manual - MongoDB Docs
MongoDB CRUD Operations - Database Manual - MongoDB Docs
Model Data for Atomic Operations - Database Manual - MongoDB Docs

Modelling Entity Relations In MongoDB | Alexander Paterson populating reference with $match and $unwind
如何将关系型数据导入 MongoDB?

Mongoose v9.6.3: Query Population
mongoose: Referencing schema in properties or arrays | Alexander Zeitler

A Node.js Perspective on MongoDB 3.4: Collations | www.thecodebarbarian.com

Thinking in Documents: Part 1 | MongoDB
Thinking in Documents: Part 2 | MongoDB
MongoDB - Thinking in Documents - agile-code.com

6 Rules of Thumb for MongoDB Schema Design: Part 1 | MongoDB
6 Rules of Thumb for MongoDB Schema Design: Part 2 | MongoDB
6 Rules of Thumb for MongoDB Schema Design: Part 3 | MongoDB

Aggregation

MongoDB 5.0 deprecated map-reduce and improved aggregation pipeline
use $lookup and $unwind for "joining" operations

Aggregation Operations — MongoDB Manual
Complete Aggregation Pipeline Tutorials - Database Manual - MongoDB Docs
Aggregation Reference — MongoDB Manual
Aggregation Stages - Database Manual - MongoDB Docs
Expressions - Database Manual - MongoDB Docs operators can also be used for stages
Updates with Aggregation Pipeline - Database Manual - MongoDB Docs
MongoDB Aggregation: tutorial with examples and exercises | Studio 3T
An Introduction to Mongoose Aggregate - Mastering JS

$lookup is used for join, $unwind is used for flatten array (expanding to multiple documents so the array elements are top level documents)
MongoDB Join Two Collections Simplified | Hevo
MongoDB $lookup Example | MongoDB Aggregation Pipeline

Tips and Tricks

Backup MongoDB inside of Docker the right way - cupcakearmy

Using MongoDB as realtime DB with nodeJS. - Noteworthy - The Journal Blog need replica sets instead of stand along server

How to traverse MongoDB super-large collections efficiently? | Develop Paper
Henrique S. Coelho - hcoelho.com - Fixing memory problems with Node.js and Mongo DB

node.js - Mongoose (mongodb) batch insert? - Stack Overflow no need to use Bulk API, Model.collection.insertMany() is fast enough (and without out of heap issue) (Model.insertMany() suffers from these issues)
javascript - Bulk insert in MongoDB using mongoose - Stack Overflow

mongodb - Difference between findOneAndDelete() and findOneAndRemove() - Stack Overflow prefer findOneAndDelete(), the native MongoDB function

mongodb - Possibility of duplicate Mongo ObjectId's being generated in two different collections? - Stack Overflow

feliixx/mgodatagen: Generate random data for MongoDB

Call function

deprecated, use Aggregation instead

$function (expression operator) - Database Manual - MongoDB Docs
Using $function in updateMany not working - Working with Data - MongoDB Developer Community Forums

the function has to be stringified

collection.updateMany(QUERY, [
  {
    $addFields: {
      field: {
        $function: { args: ["$field"], lang: "js", body: "function(field) {}" },
      },
    },
  },
]);