What is a document and a collection in MongoDB?

BeginnerConceptMongoDB
Answer

Short answer

A document is a single record stored as a JSON-like object (BSON) with fields, nested objects and arrays. A collection is a group of documents — similar to a table, but documents in the same collection don't need identical fields.

Example

// collection: customers
{ _id: ObjectId("..."), name: "Asha", email: "[email protected]", address: { city: "Pune" } }
{ _id: ObjectId("..."), name: "Ravi", email: "[email protected]", phone: "+91-98...", tags: ["vip"] }

Both live in the same collection even though their fields differ.

Mapping to SQL

SQL MongoDB
database database
table collection
row document
column field

Limits worth knowing

  • Maximum document size: 16 MB.
  • Every document has a unique _id (MongoDB adds an ObjectId if you don't).

What to say in the interview

"A document is a BSON record with fields, nested objects and arrays; a collection groups documents without enforcing a fixed schema. It's roughly table and row in SQL terms, with a 16 MB document limit and a mandatory _id."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: MongoDB basics

More on MongoDB