54 MongoDB interview questions with answers
54 MongoDB interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
All MongoDB interview questions
What is MongoDB and when should you choose it?
What are documents, collections and databases in MongoDB?
How is BSON different from JSON?
How do `findOne`, `find`, `insertOne`, and `updateOne` work in MongoDB?
Should you embed or reference documents in MongoDB?
How does MongoDB document size limit affect schema design?
What do indexes help with in MongoDB and what are the trade-offs?
How should you choose field order in a MongoDB compound index?
What is a multikey index?
When should you use a TTL index in MongoDB?
What is `ObjectId` in MongoDB?
What is `$lookup` in MongoDB and what are its risks?
What is the purpose of `$unwind` in the aggregation pipeline?
Does MongoDB support ACID transactions?
What problem does sharding in MongoDB solve?
What is an upsert in MongoDB?
What is write concern in MongoDB?
What is read preference in MongoDB?
What is a `Cursor` in MongoDB and why is pagination needed?
When should you use bulk operations in MongoDB?
What is the oplog in MongoDB?
What is the schema versioning pattern?
What is a sharding key in MongoDB and how to choose a good one?
How do you perform schema migrations in MongoDB?
What is the difference between PostgreSQL B-tree index and MongoDB B-tree index?
Why does MongoDB use BSON instead of JSON?
When does the "16MB document size limit" error usually occur and how do you fix it?
What are Capped Collections in MongoDB?
How do the `$in` and `$or` operators differ in terms of performance?
Explain "Eventual Consistency" when reading from a Secondary node.
What is GridFS and when should you use it?
How do multi-document transactions work in MongoDB?
What is the difference between `updateOne` and `replaceOne`?
How does locking work in MongoDB?
How do you implement optimistic concurrency in MongoDB?
How should multi-tenant MongoDB be designed?
Where do you start debugging slow MongoDB queries?
When should you not use MongoDB?
After running `explain()`, what should you look at first to spot a problem?
In an aggregation pipeline, why should `$match` come as early as possible?
Why should you avoid letting an array inside a document grow without bound?
What is a MongoDB change stream and what is it used for?
Posts and comments: embed comments in the post or use a separate collection? What drives the decision?
What is the ESR rule for ordering fields in a compound index? Why do sorted queries often hit a memory limit error?
The index exists but the query still scans the whole collection — when does MongoDB skip an index?
What is a covered query and how do you make one?
How do partial and sparse indexes differ, and when do you use each?
An aggregation fails with a 100MB limit at `$group`. Is enabling `allowDiskUse` the right fix?
MongoDB is schemaless — how do you stop malformed data from entering a collection?
A system writes one sensor reading per second per device. How do you design the collection to avoid billions of tiny documents?
What actually goes wrong if you pick the wrong shard key, and can it be fixed?
How do chunks and the balancer work in a sharded cluster? How do you deal with a jumbo chunk?
The replica set primary dies mid-write — what happens to the in-flight writes?
New code needs a field that 50 million existing documents lack. How do you roll it out with no downtime?