Sefism MongoDB Cheat Sheet
The companion to the MongoDB roadmap in JavaScript, Python and Java editions: documents and setup, CRUD and query operators, arrays and nested documents, schema design patterns, indexes and explain plans, the aggregation pipeline, MongoDB from your code, and transactions, replication and operations. Each of its 77 concepts is a line or two with the syntax and the classic mistake to avoid.
8
Sefism · Oct 2026
77
Sefism · Oct 2026
3 (JavaScript, Python, Java)
Sefism · Oct 2026
2
Sefism · Oct 2026
Cheat sheet
Web Development
Sefism
Reference
Beginner
Free
What this cheat sheet is
The MongoDB cheat sheet is the companion to the MongoDB roadmap, for students and early-career engineers learning MongoDB on a real cluster. It goes from the first document to data modelling, indexes, the aggregation pipeline, transactions and using MongoDB safely from application code. Each idea is revised in a line or two, with the syntax and the classic mistake to spot before you make it.
Who it is for
Anyone writing MongoDB queries who keeps opening the manual for the same five things: how $elemMatch differs from a plain array match, which order compound index fields go in, what $unwind does to a total, how write concern works. It assumes you have a cluster to try things on, whether a free Atlas cluster or a local server, and that you will try each entry in mongosh rather than just read it.
Editions
There are three editions, matching the roadmap's languages: JavaScript, Python and Java. Every edition has the same eight chapters and 77 concepts. Shell snippets are mongosh in every edition. Application code follows your language: the Node.js driver and Mongoose, PyMongo with Pydantic models, or the Java driver and Spring Data MongoDB. That shows most in chapter 7, where connecting once per process, schemas in code, blocking operator injection, catching duplicate key errors, range pagination and change streams each come with a snippet in your language.
Chapter by chapter
- Documents and your setup (8 concepts). The document model, BSON and its types, databases and collections, ObjectId and
_id, an Atlas free cluster, mongosh, Compass and a sample dataset. - Reading and writing documents (10 concepts).
insertOneandinsertMany,findand query filters, query operators, projection,sort,skipandlimit, update operators, upserts,replaceOneversusupdateOne,deleteOneanddeleteMany, and cursors. - Arrays and nested documents (6 concepts). Dot notation, querying arrays,
$elemMatch, array update operators, positional operators, and the document size limit. - Data modelling and schema design (12 concepts, the largest chapter). Query-driven design, embedding, referencing, relationship cardinality, the extended reference, subset, computed, bucket, outlier and schema versioning patterns, schema validation, and the unbounded array anti-pattern.
- Indexes and query plans (10 concepts). Indexes, compound indexes, the ESR rule, multikey, unique, partial and TTL indexes, text search,
explainand query plans, and covered queries. - The aggregation pipeline (11 concepts). The pipeline,
$match,$group, accumulators,$unwind,$lookup,$facet,$setand$project,$mergeand$out, pipeline limits and views. - MongoDB from your code (9 concepts). Driver, connection string, connection pool, ODM and schemas in code, NoSQL operator injection, duplicate key errors, range pagination, change streams and retryable writes.
- Transactions, replication and operations (11 concepts). Write concern, read concern, read preference, replica sets, multi-document transactions, sharding, shard keys, users and role-based access, network access, backups and restore tests, and monitoring and slow queries.
Tips worth pinning
- Design documents from the queries your app runs, not from the entities on a diagram.
- Embed what is read together and bounded in size; reference what grows without limit or is shared.
- Before any
deleteManyorupdateMany, run the same filter throughcountDocumentsand check the number. - Order compound index fields by equality, then sort, then range.
- Put
$matchas early as possible in every aggregation pipeline. - Never pass a request body straight into a filter: check that each value is the type you expect.
How to use it with the roadmap
- After each stage, read the chapter and run two or three of its examples against your sample dataset.
- Before designing a new collection, reread chapter 4 with your query list in hand. It is the chapter that prevents most slow MongoDB projects.
- When a query is slow, go to chapter 5 before adding anything, and run
explainfirst. - Before you deploy, read chapter 8 end to end: write concern, users, network access and a restore you have actually tested.
How it works on Sefism
Everything on Sefism is free to learn from. The public page at MongoDB cheat sheet shows every chapter title, with the first two chapters open in full. Later chapters show their title, a short introduction and how many concepts they hold.
Keeping the sheet uses credits, and it is yours for good after that. Adding the MongoDB roadmap to your dashboard also opens this sheet, so if you plan to follow the roadmap you do not need to keep the sheet separately. New members get starting credits when they join, and the first roadmap is free. Create a free account to get started, and if a concept still does not make sense after reading it, ask Tauseef a question.
Related on Sefism
- Mongo Playground, for trying a filter or pipeline on your own documents
- MongoDB University, for deeper courses on each chapter
- The SQL and databases cheat sheet, for comparing the two models
Frequently asked questions
Does it work with Mongoose? Yes. In the JavaScript edition, application code uses the Node.js driver and Mongoose, while shell snippets are mongosh. The Python edition uses PyMongo with Pydantic models, and the Java edition the Java driver and Spring Data MongoDB.
Which chapter matters most? Data modelling, and it is the largest chapter for that reason. Most performance problems trace back to documents shaped like relational tables or arrays that grow forever.
Is there anything on Atlas? Chapter 1 covers setting up a free Atlas cluster, and chapter 8 covers network access, users and monitoring on a real replica set.
Ready to start?
Opens on Sefism in a new tab.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
Follow along
New writing, resources and project ideas land here first.