109 questions in 9 topics
MongoDB Basics Interview Questions
What a first MongoDB round checks: documents and collections, BSON, the _id field and how MongoDB differs from a SQL database.
- What is MongoDB?
- What is the difference between MongoDB and a SQL database?
- What are documents and collections in MongoDB?
- What is BSON, and why does MongoDB use it instead of JSON?
MongoDB Query Interview Questions
Reading data with find: filters, comparison and logical operators, projection, sorting, pagination, and queries on arrays and embedded documents.
- What are the CRUD operations in MongoDB?
- What is the difference between
findandfindOne? - Which comparison operators does MongoDB have?
- How do you write AND and OR conditions in MongoDB?
MongoDB CRUD Interview Questions
Changing data safely: update operators, upserts, the counts an update returns, array updates, bulk inserts and deletes.
- What is the difference between
updateOne,updateManyandreplaceOne? - Which update operators should you know?
- What is the difference between
$pushand$addToSet? - What does an upsert do when no document matches?
MongoDB Aggregation Interview Questions
The aggregation pipeline: its stages, $group, $unwind, joins with $lookup, top N per group, $facet and the memory limits.
- What is the aggregation pipeline?
- Which aggregation stages should you know?
- When do you use
aggregateinstead offind? - How do you write SQL's
GROUP BY ... HAVINGin MongoDB?
MongoDB Indexing Interview Questions
How indexes speed up reads: single-field, compound, multikey, unique, partial and TTL indexes, the ESR rule and covered queries.
- What is an index in MongoDB, and why use one?
- How do you create an index?
- Can two documents without the field share a unique index?
- How do you choose the field order in a compound index?
MongoDB Schema Design Interview Questions
Modeling data for the reads your app makes: embedding versus references, relationships, growing arrays and the patterns built on them.
- When should you embed documents and when should you reference them?
- How is schema design in MongoDB different from SQL?
- How do you model a one-to-many relationship?
- How do you model a many-to-many relationship?
MongoDB Transactions, Replication and Sharding Questions
How MongoDB keeps data consistent and available: ACID transactions, replica sets and failover, and scaling out with sharding and shard keys.
- Does MongoDB support ACID transactions?
- How do you run a transaction with the Node.js driver?
- What are the limits and costs of MongoDB transactions?
- What is a replica set?
Mongoose Interview Questions
Mongoose, the Node.js ODM for MongoDB: schemas, models, validation, middleware, populate, lean and the traps around them.
- What is Mongoose, and why use it instead of the MongoDB driver?
- What is the difference between a schema, a model and a document in Mongoose?
- How does validation work in Mongoose?
- Do Mongoose validators run on
updateOneandfindOneAndUpdate?
Advanced MongoDB Interview Questions
Running MongoDB in production: slow queries, query plans, write and read concerns, change streams, connections, memory, security and safe concurrent updates.
- How do you find and fix a slow query in MongoDB?
- How does MongoDB choose a query plan?
- What is write concern?
- What is read concern?
Frequently Asked Questions
How do I prepare for a MongoDB interview?
Start with CRUD and query operators until you can write filters without looking them up, including arrays and embedded documents. Then learn the aggregation pipeline, indexes with the ESR rule, and embedding versus referencing. Model one small app, such as a shop or a blog, and explain your choices out loud. Finish with replication, sharding and transactions as concepts.
What MongoDB questions are asked to freshers and to experienced developers?
Freshers get definitions with a short query: documents, BSON, _id, SQL versus NoSQL, CRUD, operators and a simple $group. With a few years of experience, expect index design, aggregation, schema design trade-offs and Mongoose. Senior rounds focus on production: slow queries and explain, write and read concerns, replication, sharding and shard keys.
Do I need to know Mongoose for a MongoDB interview?
For Node.js roles, often yes: Mongoose is the most widely used MongoDB ODM for Node.js, so if the job's stack has it, expect schemas, validation, middleware and populate. Knowing the plain driver as well lets you explain what Mongoose does underneath and when you would skip it.
Should I write MongoDB queries in shell syntax or driver syntax in an interview?
Shell syntax (db.orders.find(...)) is the common language, so use it unless the interviewer asks for your stack. The Node.js driver uses the same method names and documents; the differences are await, getting a collection from client.db(), and toArray() on cursors.
How long does it take to prepare for a MongoDB interview?
It depends on what you already know. If you know a SQL database and JavaScript, a plan of one to two weeks covers it: a few days on queries and updates, a few on aggregation and indexes, and the rest on schema design, replication and sharding concepts and practice questions. Without a database background, learn the basics of data modeling first.