Databases, Collections, and Namespaces
Learners will create a database, add collections, and understand how MongoDB organises data at the namespace level.
MongoDB's Three-Level Hierarchy
MongoDB nests data in three levels: Database, Collection, Document. It mirrors SQL's database, table, row — and one server can hold many of each.
What Is a Namespace?
A namespace names a collection by combining database and collection with a dot, like myapp.users. You'll see this notation in logs and explain output.
// Namespace: database.collection
// 'shop' database, 'products' collection:
use shop
db.products.find({})
// MongoDB internally refers to this as 'shop.products'
// You can also reference it explicitly:
db.getSiblingDB('shop').getCollection('products').find({})All lessons in this course
- What Is a BSON Document?
- Collections vs SQL Tables
- Databases, Collections, and Namespaces
- The mongosh Shell Essentials