Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
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 dbsoutput - A database becomes visible only after adding at least one collection with data
- Use
use databaseNameto 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.
Advertisements
