CPCODELAB
MongoDB

Collections and Databases

6 min read

Organising Data: Databases and Collections

MongoDB groups documents into collections (similar to tables) and collections live inside a database. A single MongoDB server can host many databases.

  • Database — top-level namespace (e.g. school)
  • Collection — a group of related documents (e.g. students, courses)
  • Document — a single JSON-like record
js
// Switch to (or create) a database in mongosh
use school

// List all collections
show collections

// MongoDB creates the database and collection
// automatically on first insert — no CREATE TABLE needed

Databases and collections are created lazily — they appear the moment you insert the first document. There is no DDL step.

Ready to test yourself?
Practice MongoDB— quiz & coding exercises