Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
MongoDB Basics  ›  Lesson

MongoDB Terminology

MongoDB Terminology 12 minA MongoDB deployment holds databases, databases hold collections, collections hold documents, and every document has a unique _id field that acts as its primary key.

MongoDB Terminology

Every MongoDB tutorial throws the same five words at you in the first minute. Learn them once, map them to what you already know, and the rest of this course reads easily.

The rule

Databases hold collections, collections hold documents, and every document has an _id.

MongoDB Relational cousin Bookshop example
database database bookshop
collection table books
document row one book
field column title
_id primary key 1

A few rules make the words precise:

  • _id is required and unique in its collection. If you insert a document without one, MongoDB adds an ObjectId, a 12-byte value that is unique in practice. You may choose your own _id (this course uses small numbers so examples stay readable). It cannot be changed after insert.
  • Collections and databases appear on first write. use bookshop switches to the name; the first insert creates both.
  • A collection has no fixed columns. Documents in it usually look alike, but they are allowed to differ.

Here is the running example for the whole course, the books collection:

_id title author year price stock genres
1 Dune Frank Herbert 1965 9.99 12 sci-fi, classic
2 Neuromancer William Gibson 1984 8.5 0 sci-fi, cyberpunk
3 Emma Jane Austen 1815 4.25 7 classic, romance
4 The Hobbit J.R.R. Tolkien 1937 7.99 3 fantasy, classic, adventure
5 Circe Madeline Miller 2018 12 5 fantasy, myth

Each book also has a publisher object and most have a ratings array; later lessons show those in full.

The shortcut

Read any mongosh command right to left: method, collection, database.

Reading db.books.findOne({ _id: 3 })Step 1 of 4
  1. The method

    findOne(...) is the action: return one matching document.

use bookshop
db.wishlist.insertOne({ title: "Beloved", author: "Toni Morrison" })   // creates wishlist
show collections

The trap: expecting an error when you mistype a collection name. db.bokos.insertOne(...) quietly creates a new collection called bokos.

Drills

Answer fast — trust the rule.

quick drill

In relational terms, a MongoDB collection is closest to a…

quick drill

You insert a document with no _id. What happens?

quick drill

In db.books.countDocuments(), what is books?

quick drill

You run db.bokos.insertOne({ title: "Emma" }) by mistake. What happens?

Remember

  • Databases hold collections, collections hold documents, and every document has a unique _id.
  • Shortcut: read mongosh commands right to left, method then collection then database.
  • Trap: a typo in a collection name creates a new collection instead of failing.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainTranslate the vocabulary

A teammate who knows SQL joins your MongoDB project. Explain how database, collection, document, field and _id map onto the relational words they already know, and point out one way the MongoDB version behaves differently.