Skip to main content
🎁 Exclusive Launch Deal: Premium Themes Available FREE — Grab Yours Now!
Back to Blog
General

How to Create a MongoDB Database (Beginner Guide)

admin 1 min readPublished Dec 3, 2022Updated Jul 22, 2026
How to Create a MongoDB Database (Beginner Guide)

MongoDB databases in plain English

In MongoDB, a database holds collections, and collections hold documents (JSON-like BSON records). Unlike some SQL engines, MongoDB can create a database lazily when you first write data — but being explicit helps teams stay organized.

This guide shows three practical ways to create a database: local mongosh, MongoDB Atlas, and Docker.

Option 1 — Create a database with mongosh

  1. Start MongoDB locally (or connect to a remote URI).
  2. Open the shell: mongosh
  3. Switch context: use my_app_db
  4. Create the first collection by inserting a document:
    db.users.insertOne({ email: "demo [at] example.com", createdAt: new Date() })
  5. Verify: show dbs and show collections

Until you insert data (or explicitly create a collection), some listings may hide an empty database. That is expected.

Option 2 — Create a database in MongoDB Atlas

  1. Create a free/shared cluster.
  2. Add a database user and network access rule.
  3. Open Browse CollectionsCreate Database.
  4. Provide database and collection names, then insert a sample document.
  5. Copy the connection string into your app MONGODB_URI.

Option 3 — Docker quick start

docker run -d --name mongo -p 27017:27017 mongo:7
docker exec -it mongo mongosh
use demo_db
db.products.insertOne({ name: "Theme", price: 0 })

Naming and structure tips

  • Use lowercase names with underscores or clear product prefixes.
  • Keep one database per application environment (dev/staging/prod).
  • Design collections around access patterns, not rigid SQL table clones.
  • Add indexes after you know query filters (email, slug, status).

Verify from your application

With Node drivers or Mongoose, connecting with a URI that includes the database name (or calling useDb) ensures writes land in the intended place. Always confirm in Compass or mongosh after the first migration/seed.

Common mistakes

Typos in database names (this slug historically used “databsae”), writing to test by accident, and opening production clusters without IP allowlists. Double-check URI database segments before deploying.