Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"show dbs" command only showing local database but not newly created ones

I started working with mongodb yesterday and can't seem to generate a database on the console. Every time I do the

use exampledb
switched to db exampledb

but for some reason I still generate only my locals..?

show dbs
local  0.078GB

I created a folder called /data/db in my root directory (following the tutorial) so I'm not sure what I am missing... help appreciated!

like image 462
kkomaz Avatar asked Feb 10 '23 01:02

kkomaz


2 Answers

You are not missing anything. exampledb will be shown (using show dbs) only when you insert atleast one document in it. You can add collections manually if you want using db.createCollection().

like image 56
Dev Avatar answered Feb 13 '23 02:02

Dev


Your database need to have atleast one document inside. First we need to add atleast one document into the selected database.

Example:

db.mycollection.insert({"name":"Max"}) 

where db is the general term not the name of the database and mycollection is the name of your collection, inside the insert give as key value pairs)

After that you can see your database.

like image 35
anoja madusanka Avatar answered Feb 13 '23 01:02

anoja madusanka