MongoDB Fundamentals
What is MongoDB?
A document database, where it fits, and when it is — and is not — the right store.
MongoDB stores data as documents — JSON-like objects — grouped into collections. A document can hold nested objects and arrays, so related data often lives together instead of being split across tables.
{
_id: ObjectId("64a1b2c3d4e5f6a7b8c90001"),
name: "Rahul",
age: 28,
city: "Bangalore",
role: "developer",
skills: ["Node.js", "MongoDB"],
isActive: true
}- This entire object is a document — one record.
- It lives in a collection, usually named
users. - That collection lives in a database, for example
app.
Why developers use it
The unit of read is often the same as the unit of write: load Rahul, change a field, save Rahul. You do not join three tables to render a profile. New fields can appear on new documents without a migration for every column.
In a Node.js backend it usually sits behind the API: the route handler talks to a collection, not to rows. Typical fits are product catalogues, user profiles, order histories you read as one blob, and content that does not all share the same shape.
When it is a good fit
- You usually load one entity and its nested data together.
- The shape of a record still changes as the product changes.
- Different documents in the same collection honestly have different fields.
When it is a poor fit
- The common read is a report across many tables — lots of joins, little nesting.
- Many rows must change together on every write, as the default path.
- The schema is already stable, relational, and well served by SQL.
Interview question
What is MongoDB?
A document database. Data is stored as BSON documents in collections. A document can nest objects and arrays, so related data often lives in one record instead of across tables.
Say document and collection, then give one access pattern. Do not recite marketing.
Interview question
Why would you choose MongoDB over a relational database?
When the unit of read is a document with nested data, when the shape still changes, or when the common path should not pay for a join. I would not pick it just because the team likes JSON.
Name a concrete access pattern, not a buzzword.