NoSQL and the Document Model

Harry · 14 Sep 2026 · 2 views
Advertisement
Advertisement

What MongoDB is

MongoDB is a document database. Instead of rows in fixed tables, it stores documents – flexible, JSON-like objects – grouped into collections. A document can hold nested objects and arrays, so related data often lives together in one record rather than being spread across many joined tables.

A document

{
  "_id": ObjectId("64af12..."),
  "name": "Ada Lovelace",
  "roles": ["admin", "developer"],
  "address": { "city": "Pune", "zip": "411001" },
  "active": true
}

Behind the scenes MongoDB stores this as BSON (Binary JSON), which adds types like dates and the 12-byte ObjectId that every document gets as its primary key in the _id field.

How it maps to SQL

If you know relational databases, this translation makes MongoDB click:

SQL to MongoDB mapping: database to database, table to collection, row to document, column to field

  • Database → Database
  • Table → Collection
  • Row → Document
  • Column → Field

Flexible schema

Documents in the same collection do not have to share the same fields. This makes iterating fast – you can add a field to new documents without a migration. The trade-off is that consistency becomes the application’s responsibility, so teams usually still agree on a schema and enforce it in code or with validation rules.

Key points

  • MongoDB stores flexible, JSON-like documents (BSON) in collections.
  • Documents can nest objects and arrays, keeping related data together.
  • Table→collection, row→document, column→field maps SQL thinking onto Mongo.
  • Schemas are flexible; enforce consistency in the app or via validation.
Share this post:

Comments (0)

Please login or register to comment.