[DOCS-7472] Comment on: "show dbs" Created: 20/Mar/16  Updated: 03/Nov/17  Resolved: 24/Mar/16

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: Docs Collector User (Inactive) Assignee: Ravind Kumar (Inactive)
Resolution: Done Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System = Windows 8.1 32 bit (Virtual Box)
MongoDB version = 3.2.3

Location: https://docs.mongodb.org/manual/reference/mongo-shell/
User-Agent: Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
Referrer: https://docs.mongodb.org/manual/search/?query=show%20dbs
Screen Resolution: 1366 x 743
repo: docs
source: reference/mongo-shell


Participants:
Days since reply: 7 years, 47 weeks, 2 days ago

 Description   

I am new to mongodb currently I'm learning from docs and tutorials available online, I need a clarification in certain Mongodb 'show dbs' command. I'm pretty sure that it would list all the databases that we've created.

but there is a slight problem I'm facing with that command
1. I've created a db using the following command
use mytestdb
2. Then I tried to view the current db using command
db
It shown my database name mytestdb
3. finally when I'm trying to see the list of available databases i've created using
show dbs
but still the list didn't consist of my recently created database "mytestdb"

I tried several time but the result is same, I searched about this similar problem in the internet I got two solutions which worked for me
1. Restart mongo client
2. Repair the db using db.repairDatabase() command

Though it worked fine I just need to know why its not refreshing in the real time, is it a feature or a bug, if its a feature I just need to know why and if I am not doing something right please educate me. I'm so much fascinated to learn mongodb completely.

Thank you so much in advance



 Comments   
Comment by Ravind Kumar (Inactive) [ 21/Mar/16 ]

Hello Sundar,

The use db command switches to the database whether it exists or not. The database exists only after a collection is created within it.

The relevant paragraph can be found in this section

If a database does not exist, MongoDB creates the database when you first store data for that database.

The db.createCollection() method creates a collection within the current active database. You can also use the db.collection.insertOne or db.collection.insertMany methods to create the collection as a part of the insertion process.

Please let us know if this answers your question. We're happy to hear about your interest in MongoDB. If you haven't already, check out https://university.mongodb.com/ for lessons on using MongoDB. The M101 courses are a good place to start.

Generated at Thu Feb 08 07:54:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.