MongoDB Tutorial 0/120 lessons ~6 min read Lesson 12
Database Creation
Creating a database in MongoDB requires zero ceremony.
Course progress0%
Focus
5 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Creating a database in MongoDB requires zero ceremony. Switch to a non-existing database name with use and the database materializes the moment you insert your first document. No CREATE DATABASE statement, no DDL.
Understanding the topic
Lifecycle of a database:
use shop— selects (or creates) the database.- Database is lazy — actually allocated on first write.
show dbslists databases that have at least one document.db.dropDatabase()deletes the current database permanently.- Databases are cheap — many SaaS apps use one DB per tenant.
Syntax reference
js
// Create / switchuse shop;// Insert (DB and collection materialize now)db.products.insertOne({ name: "Mug", price: 9.99 });// Listshow dbs;// Dropdb.dropDatabase();
Real-world use
Multi-tenant SaaS often uses one database per customer (tenant_acme, tenant_globex). This gives strong isolation and per-tenant backups for free.
Best practices
- Don't create a database 'just in case' — it stays invisible until you insert.
- Use lowercase, no spaces, no
$in DB names. - Document per-tenant or shared-tenant DB choices in your README.
Ready to mark this lesson complete?Track your journey across the entire course.