Skip to content

MongoDB Fundamentals

Database, Collection, Document and Field

The four nouns you will use in every query, mapped to how data is actually stored.

BeginnerAbout 4 minutes

Every query you write names these four things, whether you think about them or not.

  1. 01MongoDB server
  2. 02Database — app
  3. 03Collection — users, orders, products
  4. 04Document — Rahul
  5. 05Field — city, skills, isActive
use app
db.users.findOne({ name: "Rahul" })
In the shell, db is the current database; users is the collection
{
  _id: ObjectId("64a1b2c3d4e5f6a7b8c90001"),
  name: "Rahul",
  age: 28,
  city: "Bangalore",
  role: "developer",
  skills: ["Node.js", "MongoDB"],
  isActive: true
}
One document. Each key is a field.
  • Database — the application-level container. One backend usually has one (maybe a second for tests). Named app here.
  • Collection — a group of related documents. users, orders, products, reviews, employees, departments. Close to a table, without a fixed set of columns.
  • Document — a single record. Rahul is one document in users.
  • Field — a property on that document. city is a field; skills is a field whose value is an array.

In SQL: database → table → row → column. In MongoDB: database → collection → document → field. The next two lessons are about what those field values actually are (_id, dates, decimals).

Interview question

How are database, collection, document and field related?

Think about it first.