
These are the MongoDB interview questions a fresher or junior backend developer should be able to answer out loud. Read a question, answer it yourself first, then open it to check.
Basic Questions
1What is MongoDB?
MongoDB is a document-oriented NoSQL database. It stores data as BSON documents (a binary form of JSON) grouped into collections.
2How is MongoDB different from a relational database?
Relational databases use tables, rows and a fixed schema. MongoDB uses collections and documents with a flexible schema, and often embeds related data instead of joining tables.
3What are a document and a collection?
A document is a set of field-value pairs, similar to a row. A collection is a group of documents, similar to a table.
4What is BSON?
BSON is the binary format MongoDB uses to store documents. It supports types JSON lacks, such as Date, ObjectId and binary data.
5What is the _id field?
Every document needs a unique _id. If you do not supply one, MongoDB creates an ObjectId. It is indexed automatically.
6How do you insert documents?
db.students.insertOne({ name: "Asha", course: "MongoDB" })
db.students.insertMany([{ name: "Ravi" }, { name: "Meera" }])7How do you read documents with a condition?
db.students.find({ age: { $gte: 18 } }, { name: 1, _id: 0 })The first argument filters, the second (projection) picks the fields to return.
8How do you update a document?
db.students.updateOne({ name: "Asha" }, { $set: { city: "Rajkot" } })$set changes only the listed fields. replaceOne replaces the whole document.
9How do you delete documents?
Use deleteOne(filter) for the first match and deleteMany(filter) for all matches.
Indexing and Aggregation
10What is an index and why use it?
An index is a data structure that lets MongoDB find documents without scanning the whole collection. It speeds up reads and adds some cost to writes and storage.
db.students.createIndex({ email: 1 }, { unique: true })11What is a compound index?
An index on more than one field, for example { course: 1, age: -1 }. Field order matters: queries benefit when they use the leading fields (the prefix).
12How do you check whether a query uses an index?
Run db.students.find({...}).explain("executionStats"). IXSCAN means an index was used; COLLSCAN means a full collection scan.
13What is the aggregation pipeline?
A series of stages that transform documents step by step, such as $match, $group, $sort and $project.
db.orders.aggregate([
{ $match: { status: "paid" } },
{ $group: { _id: "$customerId", total: { $sum: "$amount" } } },
{ $sort: { total: -1 } }
])14What does $lookup do?
$lookup performs a left outer join with another collection inside an aggregation pipeline.
Schema Design, Scaling and Production
15Embedding or referencing: which should you choose?
Embed data that is read together and stays reasonably small. Reference data that is large, grows without limit, or is shared by many documents.
16What is the maximum document size?
A single BSON document can be up to 16 MB. GridFS is used to store larger files in chunks.
17What is a replica set?
A group of MongoDB servers holding the same data. One primary takes writes, secondaries copy it, and a new primary is elected if it fails.
18What is sharding?
Sharding splits data across several servers using a shard key, so a database can scale horizontally. A poorly chosen shard key causes uneven load.
19Does MongoDB support transactions?
Yes. Multi-document ACID transactions are supported on replica sets (version 4.0 onwards) and sharded clusters (4.2 onwards). Single-document writes are always atomic.
20What is a write concern?
It states how much acknowledgement a write needs. w: "majority" waits until most replica set members have it, which is safer than acknowledging from one.
21What is a TTL index?
An index on a date field that removes documents automatically after a set time. It is useful for sessions, tokens and temporary logs.
22What is MongoDB Atlas?
MongoDB's managed cloud service, handling setup, backups, monitoring and security settings.
23How do you connect MongoDB to Node.js?
Use the official mongodb driver or the Mongoose ODM, keep the connection string in an environment variable, and reuse one client across requests.
24How can you prevent NoSQL injection?
Validate input types before querying, never pass raw request objects as filters, and use a schema validator.
25What makes a query slow, and how do you fix it?
Missing indexes, returning too many fields or documents, and unbounded arrays. Check explain(), add suitable indexes, project only what you need and paginate.
Tips for the Interview
- Answer, then give an example from your own project.
- Run the queries in a free Atlas cluster or a local install before the interview.
- Say when you do not know, then explain how you would find out.
- Check the official docs for version-specific behaviour: MongoDB Manual.
New to server-side work? Start with our backend developer roadmap, or join the MongoDB course in Rajkot.
Frequently Asked Questions
Are these MongoDB interview questions enough for a fresher?
They cover the common ground. Also build one project that uses MongoDB, because interviewers often ask about your own schema and queries.
Do I need SQL if I know MongoDB?
Yes, learn both. Many companies use relational databases, and comparing the two is a frequent interview question.
How should I answer a design question?
Ask how the data will be read and written, then explain whether you would embed or reference, and which indexes you would add.
Go Beyond Memorising Answers
Codeksha's MongoDB course in Rajkot covers CRUD, schema design, indexing, aggregation and Atlas, ending with a backend project.
Get Syllabus, Fees & a Free Demo
Tell us your number and a Codeksha counsellor will call you back about the MongoDB course in Rajkot.


