Skip to content

MongoDB Fundamentals

What is MongoDB?

A document database, where it fits, and when it is — and is not — the right store.

BeginnerAbout 4 minutes

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
}
One user. Nested fields and an array sit on the same record.
  • 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?

Think about it first.

Interview question

Why would you choose MongoDB over a relational database?

Think about it first.