MongoDB interview questions: 30 questions with answers for every level
Thirty MongoDB questions sorted by level, each with a model answer, the points a strong candidate covers and the red flags worth noting.
A resume that lists MongoDB can mean two years of production work or one weekend tutorial. MongoDB interview questions are how you tell which one you are about to hire.
This guide gives you 30 MongoDB interview questions by level, each with a model answer, what strong candidates add and a red flag. It also covers coding tasks, scenarios, a scoring scale and outdated questions to drop.
For roles that span several NoSQL databases, pair it with our NoSQL developer interview questions.
TL;DR:
- MongoDB interview questions should cover the document model, CRUD, indexing, aggregation, schema design, replication, sharding and transactions, weighted by the level of the role.
- Ask juniors about documents, BSON, _id, CRUD and basic indexes. Ask mid-level developers about aggregation, embed vs reference, explain() and replica sets.
- Ask senior candidates about shard keys, transactions, the oplog, the 16 MB document limit and production incidents.
- A short practical task, such as writing a query plus the index it needs, shows more than ten definition questions.
- Drop outdated questions on MMAPv1 and map-reduce. MongoDB deprecated map-reduce in version 5.0 in favour of the aggregation pipeline.
- Score every answer on a 1 to 4 scale with written evidence, and screen with a skills test before the live interview.
What do MongoDB interview questions test?
MongoDB interview questions test nine skill areas: the document data model, CRUD queries, indexing, aggregation, schema design, replication, sharding, transactions and consistency, and performance and security. Junior roles lean on the first four. Senior roles are judged mostly on schema design, scaling and how the candidate handles production problems.
MongoDB is common enough that most backend hiring loops meet it. The Stack Overflow Developer Survey 2025 found that 24.3% of professional developers had used MongoDB in the past year, behind PostgreSQL at 58.2% and MySQL at 39.6%.
That means plenty of candidates list it on a resume, and a resume line says little about depth.
Skill area | What the candidate should be able to do | Level where it matters most |
|---|---|---|
Document model and BSON | Explain documents, collections, _id and data types | Junior |
CRUD and update operators | Write find, insert, update and delete calls with filters and projections | Junior |
Indexing | Pick single, compound and multikey indexes and read explain() | Junior to mid |
Aggregation | Build $match, $group, $lookup and $project pipelines | Mid |
Schema design | Choose embed or reference from access patterns | Mid to senior |
Replication | Explain replica sets, elections, read and write concern | Mid to senior |
Sharding | Choose a shard key and fix uneven chunks | Senior |
Transactions | Know when multi-document transactions are worth the cost | Senior |
Performance and security | Diagnose slow queries, set up auth, TLS and backups | Senior |

MongoDB interview questions for junior candidates
MongoDB interview questions for junior candidates and freshers should check the basics: what a document is, how BSON differs from JSON, what _id does, how CRUD calls work and why indexes matter. A good junior answers in plain words, writes a simple query without help and knows the limits of what they know.
1. What is MongoDB, and how is it different from a relational database?
Model answer: MongoDB is a document database. Data is stored as flexible, JSON-like documents grouped in collections, instead of rows in tables with a fixed schema.
Related data is often stored together in one document, so many reads need no joins. Relational databases normalise data across tables and join them at query time.
Strong candidates add: MongoDB still supports joins ($lookup), schema validation and multi-document transactions, so the difference is about defaults and design, not missing features.
Red flag: "MongoDB has no schema, so you never have to design one."
2. What are documents, collections and BSON?
Model answer: A document is one record made of field and value pairs. A collection is a group of documents, similar to a table.
BSON is the binary format MongoDB uses to store documents. It is faster to scan than text JSON and adds types JSON lacks, such as Date, ObjectId, Decimal128 and binary data.
Strong candidates add: Each document can be at most 16 MB, which affects how much data you should embed.
Red flag: Treating BSON and JSON as the same thing.
3. What is the _id field, and what is an ObjectId?
Model answer: Every document needs a unique _id, which acts as the primary key and is indexed automatically. If you do not set one, MongoDB creates an ObjectId: a 12-byte value that includes a timestamp, so ObjectIds sort roughly by creation time.
Strong candidates add: You can use your own _id, such as an order number, when it is unique and never changes.
Red flag: Not knowing that _id is indexed by default.
4. How do you insert, read, update and delete documents?
Model answer: Use insertOne or insertMany to add documents, find or findOne to read them, updateOne, updateMany or replaceOne to change them, and deleteOne or deleteMany to remove them. Each call takes a filter document, such as { status: "active" }.
Strong candidates add: A projection, such as { name: 1, email: 1 }, returns only the fields you need and cuts network load.
Red flag: Using updateMany or deleteMany with an empty filter without noticing it hits every document.
5. What is the difference between find() and findOne()?
Model answer: find() returns a cursor that can iterate over many matching documents. findOne() returns the first matching document, or null if nothing matches.
Strong candidates add: Cursors fetch results in batches, so large result sets do not load into memory at once.
Red flag: Thinking find() returns an array of every result in one go.
6. What do update operators like $set, $inc and $push do?
Model answer: $set sets a field's value, $inc adds a number to a field, $push appends to an array, $pull removes matching array items and $unset removes a field. Operators change only the named fields instead of replacing the whole document.
Strong candidates add: An upsert ({ upsert: true }) inserts a document when no match exists.
Red flag: Passing a full document to updateOne without an operator and expecting a partial update.
7. What is an index, and why does MongoDB need one?
Model answer: An index is a sorted structure on one or more fields that lets MongoDB find matching documents without scanning the whole collection. Without a suitable index, a query does a collection scan, which gets slower as the collection grows.
Strong candidates add: Indexes speed up reads but slow writes and use memory, so you index for your real queries, not every field.
Red flag: "Add an index on every field to be safe."
8. When would you choose MongoDB, and when would you not?
Model answer: MongoDB suits data that is naturally shaped as documents, changes structure often or needs to scale out across servers: product catalogues, content, user profiles, event data and IoT readings. A relational database is often a better fit for heavily related data with many cross-table joins and strict reporting needs.
Strong candidates add: A concrete example from their own work, including what they would do differently.
Red flag: Saying MongoDB is always faster or always better.
MongoDB interview questions for mid-level developers
MongoDB interview questions for mid-level developers should move from syntax to judgment: building aggregation pipelines, choosing between embedding and referencing, reading explain() plans, and explaining how replica sets and write concern protect data.
9. What is the aggregation pipeline, and which stages do you use most?
Model answer: The aggregation pipeline passes documents through a sequence of stages, each transforming the results of the last. Common stages are $match (filter), $group (summarise), $project (shape fields), $sort, $limit, $unwind (split arrays) and $lookup (join another collection).
Strong candidates add: Put $match and $sort early so the pipeline can use indexes and handle fewer documents.
Red flag: Running a big $group before filtering.
10. How do you decide between embedding and referencing?
Model answer: Embed data that is read together and has a bounded size, such as an order's line items or a user's addresses. Reference data that is large, grows without limit, or is shared and updated in many places, such as comments on a viral post or products used by many orders.
MongoDB's data modeling guidance sums it up as "data that's accessed together should be stored together".
Strong candidates add: The decision starts from the application's read and write patterns, not from a normalised diagram.
Red flag: Copying a relational schema table by table into collections.
11. Which index types does MongoDB support?
Model answer: Single field, compound, multikey (for arrays), text, geospatial (2dsphere), hashed (often for sharding), wildcard, TTL (expires documents after a set time) and partial or unique indexes.
Strong candidates add: The equality, sort, range rule for compound index field order: fields matched exactly first, sort fields next, range filters last.
Red flag: Not knowing that compound index field order changes which queries the index can serve.
12. How do you read an explain() plan?
Model answer: Run .explain("executionStats") on the query. Check whether the winning plan uses IXSCAN (index scan) or COLLSCAN (collection scan), and compare totalDocsExamined with nReturned.
A large gap between the two means the index is weak or missing.
Strong candidates add: An in-memory SORT stage in the plan means no index supports the sort.
Red flag: Judging performance only by how fast a query feels on a laptop.
13. What is a replica set, and how does failover work?
Model answer: A replica set is a group of MongoDB servers holding the same data: one primary takes writes, and secondaries copy changes from it. If the primary fails, the remaining members hold an election and promote a secondary, usually within seconds.
Strong candidates add: Use an odd number of voting members, and spread them across zones so one outage cannot take a majority.
Red flag: Confusing replication (copies for availability) with sharding (splitting data for scale).
14. What are read concern and write concern?
Model answer: Write concern sets how many members must acknowledge a write before it counts as successful, for example w: "majority". Read concern sets how durable the data you read must be, for example "majority" returns only data that a majority has confirmed.
Strong candidates add: Read preference (primary or secondary) is a different setting from read concern.
Red flag: Using w: 0 for important data without knowing writes can be lost.
15. How does $lookup work, and when should you avoid it?
Model answer: $lookup is an aggregation stage that joins documents from another collection, much like a left outer join. Use it for occasional reports or admin views.
Avoid it on hot read paths where the same join runs thousands of times a minute. Embed or duplicate the needed fields instead.
Strong candidates add: The joined collection's field should be indexed.
Red flag: Building every screen on chains of $lookup stages.
16. How do you enforce structure in a flexible-schema database?
Model answer: Use schema validation with a $jsonSchema rule on the collection to require fields, types and allowed values. Many teams also enforce structure in the application layer, for example with an ODM such as Mongoose.
Strong candidates add: Validation level and action settings let you roll rules out without breaking old documents.
Red flag: "Flexible schema means data quality is the front end's problem."
Advanced MongoDB interview questions for experienced candidates
Advanced MongoDB interview questions for experienced candidates should test transactions, sharding, the oplog, document size limits, change streams, security and backups. Senior answers should come with trade-offs, numbers and stories from real systems.
A candidate with five years of MongoDB work should explain at least one incident they fixed.
17. Does MongoDB support ACID transactions, and when should you use them?
Model answer: Yes. A single-document write is always atomic.
Multi-document transactions arrived in version 4.0 for replica sets and 4.2 for sharded clusters. Use them when several documents must change together, such as moving money between two accounts.
Strong candidates add: Transactions cost performance. The MongoDB transactions documentation says they "should not be a replacement for effective schema design".
Good modeling should keep most writes to one document.
Red flag: "MongoDB is not ACID." That has not been true since 2018.
18. How does sharding work, and how do you choose a shard key?
Model answer: Sharding splits a collection across several replica sets (shards) by a shard key. A router (mongos) sends each query to the right shards using the cluster's metadata.
A good shard key has high cardinality, spreads writes evenly and matches the most common query filter.
Strong candidates add: Ranged keys on a steadily rising value, like a timestamp, send all new writes to one shard. Hashed keys spread writes but make range queries hit every shard.
Red flag: Picking a low-cardinality key such as country or status.
19. What is the oplog, and why does its size matter?
Model answer: The oplog is a capped collection on each replica set member that records every change. Secondaries replay it to stay in sync.
If a secondary falls further behind than the oplog window, it cannot catch up and needs a full resync.
Strong candidates add: Size the oplog to cover planned maintenance and the worst replication lag you expect.
Red flag: Not knowing what replication lag is.
20. What is a covered query?
Model answer: A covered query is answered entirely from an index: every field in the filter and the projection is in the index, and _id is excluded unless indexed. MongoDB never reads the documents, so the query is fast.
Strong candidates add: explain() shows zero totalDocsExamined for a covered query.
Red flag: Confusing covered queries with simply using an index.
21. How do you handle unbounded arrays and the 16 MB document limit?
Model answer: Do not let arrays grow without limit inside one document. Use the bucket pattern (group readings into one document per hour or per 100 items), the subset pattern (keep the latest items embedded and the rest in another collection) or a plain reference.
Strong candidates add: Large arrays also make updates and multikey indexes slower long before the 16 MB limit.
Red flag: Storing every comment or event in one ever-growing array.
22. What are change streams used for?
Model answer: Change streams let an application subscribe to inserts, updates and deletes on a collection, database or cluster in real time. Common uses are syncing a search index, sending notifications, cache invalidation and event-driven microservices.
Strong candidates add: A resume token lets a consumer restart from where it stopped. Change streams need a replica set or sharded cluster.
Red flag: Polling a collection every second instead.
23. How do you secure a production MongoDB deployment?
Model answer: Turn on authentication and role-based access control, give each application the least privilege it needs, require TLS, bind to private networks only, encrypt data at rest, and enable auditing where compliance requires it.
Strong candidates add: A database reachable from the public internet is open to anyone who finds it, so network rules matter as much as passwords.
Red flag: Running a database open to the internet "for now".
24. How do you back up and restore MongoDB at scale?
Model answer: mongodump and mongorestore work for small databases. Large or sharded deployments use filesystem or cloud snapshots, or a managed backup service with point-in-time recovery.
Restores should be tested on a schedule, not assumed.
Strong candidates add: A recovery time and recovery point target agreed with the business.
Red flag: No memory of ever testing a restore.
Which MongoDB coding interview questions work best?
The best MongoDB coding interview questions are short tasks on a realistic dataset: write a filtered query with the index it needs, build an aggregation that answers a business question, and design a schema from an access pattern. Each task takes 10 to 20 minutes and shows how the candidate thinks, not what they memorised.
25. Write a query for the 10 most recent shipped orders of one customer, with three fields
Sample answer: db.orders.find({ customerId: 42, status: "shipped" }, { orderId: 1, total: 1, createdAt: 1, _id: 0 }).sort({ createdAt: -1 }).limit(10)
Listen for: A compound index { customerId: 1, status: 1, createdAt: -1 } that supports both the filter and the sort.
26. Write an aggregation that returns revenue per product category for 2026, highest first
Sample answer: db.orders.aggregate([ { $match: { createdAt: { $gte: ISODate("2026-01-01"), $lt: ISODate("2027-01-01") } } }, { $unwind: "$items" }, { $group: { _id: "$items.category", revenue: { $sum: { $multiply: ["$items.price", "$items.qty"] } } } }, { $sort: { revenue: -1 } } ])
Listen for: $match first so the date index is used, and a question about whether cancelled orders should count.
27. Design a schema for a blog with authors, posts and comments
Sample answer: Store authors in their own collection. Store posts with the author's _id plus a copy of the author's name for fast display.
Keep comments in a separate collection with the post's _id, and embed only the latest few comments in the post if the page shows them.
Listen for: Questions about read patterns first, such as "How many comments does a popular post get?"
Pro tip: Give every candidate the same small dataset and the same three tasks. Testlify's coding tests let you set practical tasks like these and score every candidate against the same expected output.
What scenario-based MongoDB questions show real experience?
Scenario-based MongoDB questions show real experience because a candidate cannot answer them from a list of definitions. Describe a production problem and ask for the first five things they would check.
Experienced candidates ask clarifying questions, measure before changing anything and explain how they would stop the problem from coming back.
28. A query that took 20 ms now takes 4 seconds. What do you do?
Model answer: Check the slow query log or profiler, run explain() on the query, and compare the plan with the expected index.
Look for a changed query shape, a dropped or unused index, data growth, or a lock or resource problem on the server. Fix the index or query, then add monitoring for the query.
Strong candidates add: They ask what changed recently, such as a deploy, a new query shape or a data load. They fix the cause and add an alert on query time.
Red flag: Adding indexes at random without reading the explain() plan first.
29. One shard holds most of the data and traffic. Why, and how do you fix it?
Model answer: The shard key is probably monotonic or low-cardinality, creating a hot shard. Check chunk distribution and the balancer.
Longer term, reshard on a better key (supported since version 5.0) or add a hashed or compound key that spreads writes.
Strong candidates add: They check whether the traffic skew comes from the key or from a few very busy values. They also plan the resharding work for a quiet period.
Red flag: Suggesting more shards alone will fix a hot shard caused by a poor shard key.
30. Secondaries are minutes behind the primary. What do you check?
Model answer: Check replication lag and the oplog window first, then secondary hardware, disk speed and network. Look for heavy writes, large index builds or long-running queries on the secondaries.
If lag nears the oplog window, act fast to avoid a full resync.
Strong candidates add: They check whether reads from secondaries are slowing replication. They also look at write concern settings and whether the lag is steady or spiking.
Red flag: Restarting the secondaries straight away without checking the cause or the oplog window.
How do MongoDB questions change by role?
MongoDB questions change with the job: backend and MERN developers need query, schema and aggregation depth; database administrators need replication, backups, security and performance tuning; data engineers need aggregation, change streams and pipeline design. Pick 8 to 12 questions that match the role's daily work instead of using one generic list.
Role | Focus questions | Practical task |
|---|---|---|
Backend or MERN developer | 4, 6, 9, 10, 11, 12, 15, 17 | Query with index, schema from access pattern |
Database administrator | 13, 14, 18, 19, 23, 24, 29, 30 | Read an explain() plan, plan a restore |
Data engineer | 9, 15, 21, 22, 26 | Aggregation for a business report |
Full stack (junior) | 1 to 8 | Simple CRUD and one index |
For role-specific lists, see our MERN stack developer interview questions, database administrator interview questions and the MongoDB developer job description template.
How should you score answers to MongoDB interview questions?
Score answers to MongoDB interview questions on a simple 1 to 4 scale, with one line of evidence per score, so every interviewer judges candidates the same way. Agree on what a 3 looks like for each question before the first interview, and score right after each answer, not at the end of the day.
Score | What the answer sounds like | Example (question 10, embed vs reference) |
|---|---|---|
1: Weak | Wrong or memorised words with no understanding | "Always embed; it is faster." |
2: Basic | Correct definition, no trade-offs | Explains both options but cannot say when to pick each |
3: Solid | Correct, with trade-offs and an example | Embeds bounded data, references unbounded or shared data |
4: Strong | Solid plus real-world limits and experience | Adds the 16 MB limit, write patterns and a past redesign |
Use a written interview scorecard for each round, and keep the same questions for every candidate in a role. A structured interview makes MongoDB scores comparable across interviewers and easier to defend.
Key takeaway: A candidate who scores 3 across schema design, indexing and aggregation is usually a safer hire than one who scores 4 on definitions and 2 on design.
Which MongoDB interview questions are outdated?
Several MongoDB interview questions still found online are outdated: questions about the MMAPv1 storage engine, map-reduce as a core skill, "MongoDB has no transactions", and 32-bit system limits. Asking them rewards memorised old answers and penalises candidates who know current MongoDB.
- MMAPv1 vs WiredTiger: WiredTiger has been the default storage engine for years and MMAPv1 is gone from current versions. Ask about WiredTiger cache sizing instead.
- Map-reduce: The MongoDB map-reduce page marks it deprecated since version 5.0 and points users to the aggregation pipeline. Ask for an aggregation instead.
- "Does MongoDB support transactions?" as a yes or no trick: Ask when the candidate would use a transaction and what it costs.
- 32-bit limits and old locking questions: These describe very old versions. Ask about current concurrency and the oplog.
Where do MongoDB interview questions fit in the hiring process?
MongoDB interview questions work best after a short skills test has filtered the pool. Run a 10 to 20 minute MongoDB test first, use the technical interview for the questions above, add one practical task, finish with a scenario round for senior roles, and decide in a scored debrief.
The hiring process below has five steps, each one narrowing the pool before the next:
- Skills test: A short online test removes candidates who list MongoDB but cannot write a query. The Testlify MongoDB Database test is a 10-minute, 12-question test covering CRUD, indexing, aggregation, sharding, transactions and security.
- Technical interview: Ask 8 to 12 questions from the level that fits the role, scored on the 1 to 4 scale.
- Practical task: One query, aggregation or schema task on a shared dataset.
- Scenario round: For senior and DBA roles, two production scenarios.
- Scored debrief: Compare scores and evidence, not impressions.
Testing skills first also widens the pool. According to LinkedIn Economic Graph research from March 2025, a skills-based approach could grow the US talent pool for a typical job by 15.9 times compared with hiring only people who held the same job title.
Testlify supports this with 3,500+ tests, 25+ question types including coding questions, and 20+ proctoring checks through its anti-cheating and proctoring features.
Ready to screen MongoDB candidates before the interview?
Book a demo to see how Testlify can screen MongoDB candidates before the first call. You can also start a 7-day free trial, no credit card needed.
Send the NoSQL test or the MongoDB Database test before the first call, then use the questions in this guide for the shortlist. Browse the Testlify test library to find more role-specific tests.
Frequently asked questions (FAQs)
People and Talent Partner
Arushi Shah runs day-to-day talent acquisition and candidate experience at Testlify. She writes on interviewing, structured hiring, and giving candidates a fair, fast process.
LinkedInRelated resources
View all
Interview questions
40 delivery driver interview questions and what good answers sound like

Interview questions
Lab assistant interview questions: 30 to ask, with strong answers

Interview questions
30 scenario based interview questions to ask candidates

Interview questions
30 Selenium interview questions to ask and what strong answers sound like

Interview questions
Situational based interview questions: 30 examples for hiring teams

Interview questions
40 healthcare interview questions to ask candidates, with strong answers
Get started.
Hire on proof, not resumes.
Run your first skills-based assessment free — no credit card required.