MongoDB Interview Questions and Answers
1. Basic Questions
Q: What is MongoDB?
A: MongoDB is a NoSQL, document-oriented database used for high volume data storage. It stores data in
flexible, JSON-like documents.
Q: What are the key features of MongoDB?
A: Features include schema-less architecture, high performance, scalability, replication, and indexing.
Q: How is MongoDB different from a relational database?
A: MongoDB uses documents instead of rows and collections instead of tables. It does not require a fixed
schema.
Q: What is a document in MongoDB?
A: A document is a data structure composed of field and value pairs, similar to JSON.
Q: What is a collection in MongoDB?
A: A collection is a group of MongoDB documents, similar to a table in RDBMS.
2. Data Model and Structure
Q: What is BSON in MongoDB?
A: BSON stands for Binary JSON, a binary-encoded serialization of JSON-like documents.
Q: How is data stored in MongoDB?
A: Data is stored as BSON documents in collections.
Q: What are embedded documents and referenced documents?
A: Embedded documents store data within a document; referenced documents use a reference to another
document.
Q: When should you use embedding vs referencing?
A: Embed when related data is frequently accessed together; reference when data is large or reused.
3. CRUD Operations
Q: How do you insert a document into a collection?
A: Use `db.collection.insertOne()` or `insertMany()`.
Q: How can you update a document in MongoDB?
MongoDB Interview Questions and Answers
A: Use `db.collection.updateOne()` or `updateMany()` with update operators like `$set`.
Q: How do you delete documents from a collection?
A: Use `db.collection.deleteOne()` or `deleteMany()`.
Q: Explain the difference between insertOne, insertMany, updateOne, and updateMany.
A: `insertOne`/`insertMany` insert single/multiple documents. `updateOne`/`updateMany` update one/multiple
documents.