[SERVER-18313] Commnad "show dbs" does not list all the database Created: 04/May/15  Updated: 10/Mar/23  Resolved: 13/May/15

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 3.0.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Darshit Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Capture.PNG    
Issue Links:
Related
related to DOCS-5432 Clarify "show dbs" behavior Closed
Operating System: ALL
Steps To Reproduce:

Steps:
1.) show dbs
2.) use <database_name> – <database_name> should not exists, and if it does, it should not have any collections or users associated with it.
3.) show dbs

Now, when step 3 is executed, it doesn't show database created in step 2.

Participants:

 Description   

When user says "use <database_name>", if database with that name doesn't exists, mongodb creates the database and switches to it. If database already exists, mongodb only switches to asked database in the command.

if user doesn't create any collection or add user to newly created database, mongodb doesn't show newly created database when "use <databae_name>" command is issued.



 Comments   
Comment by Sam Kleinman (Inactive) [ 07/May/15 ]

Hello,

After running some tests and poking around in the code, there are a couple of underlying issues here.

  • Databases are created and exist after inserting the first document into a collection in the database. Databases and collections are created implicitly; however, creating a database or collection object in your client does not create a database or collection. use <db> does not create new database files.
  • Empty databases are not listed in the output of show dbs. This is partially storage engine dependent. MMAPv1, it's impossible to have an extant but empty database: you cannot create a database except by inserting data. Even if you later drop that data, there is a small amount of internal overhead that remains. The one exception is that before 3.0, show dbs reported the admin database as empty in some cases, but there were no corresponding. WiredTiger does not report databases that do not have data, other storage engines may have different behavior here.

Given this, I think the behavior that you're seeing is expected. I'm going to go ahead and close this ticket, but I've sent this ticket to our documentation team who will consider the best way to clarify these expectations in the documentation.

Cheers,
sam2

Comment by Darshit [ 04/May/15 ]

There are few mistakes. Corrections are shown below.

1.) Title: Commnad "show dbs" does not list all the databases.
2.) Description: When user says "use <database_name>", if database with that name doesn't exist, mongodb creates the database and switches to it. If database already exists, mongodb only switches to asked database in the command.
if user doesn't create any collection or add user to newly created database, mongodb doesn't show newly created database when "show dbs" command is issued.

Generated at Thu Feb 08 03:47:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.