To display a database in the SHOW dbs list, do we need to add collections to it?

Yes, to display a database in the SHOW dbs list, you must create a database and add at least one collection with data to it. Empty databases are not visible in the database list. After adding collections, use the show dbs command to display all databases.

Syntax

use databaseName;
db.collectionName.insertOne({field: "value"});
show dbs;

Example

Let's create a new database and verify it appears in the database list ?

Step 1: Create Database

use webcustomertracker;
switched to db webcustomertracker

Step 2: Add Collection with Data

db.first_Collection.insertOne({"Name": "Chris"});
{
  "acknowledged": true,
  "insertedId": ObjectId("5ce2760836e8b255a5eee94a")
}

Step 3: Verify Collection Data

db.first_Collection.find();
{ "_id": ObjectId("5ce2760836e8b255a5eee94a"), "Name": "Chris" }

Step 4: Display Database List

show dbs;
admin                  0.002GB
business               0.000GB
config                 0.000GB
local                  0.000GB
webcustomertracker     0.000GB

Key Points

  • Empty databases (without collections) are not visible in show dbs output
  • A database becomes visible only after adding at least one collection with data
  • Use use databaseName to create/switch to a database
  • Collections are created automatically when you insert the first document

Conclusion

MongoDB only displays databases containing collections in the show dbs list. Create a collection with at least one document to make your database visible in the database list.

Updated on: 2026-03-15T01:32:31+05:30

132 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements