Reputation: 28074
According to this documentation using use mays
should create a db if it isn't already created:
MongoDB use DATABASE_NAME is used to create database. The command will create a new database, if it doesn't exist otherwise it will return the existing database.
So why doesn't mongo use mays
work?
root@server88-208-249-95:~# mongo use mays
MongoDB shell version: 2.6.11
connecting to: use
2015-09-16T22:17:20.316+0100 file [mays] doesn't exist
failed to load: mays
Upvotes: 5
Views: 8660
Reputation: 983
The 'use' command doesn't work with mongo command. You have to open mongo shell and then use the 'use' command.
Open terminal -> enter 'mongo' to get mongo shell -> use db_name
This will create a DB if it doesn't exists already.
A DB doesn't show up when using 'show dbs' until you create a collection in it.
Use db.createCollection("collection_name") and then use 'show dbs' and you will see your newly created DB.
Upvotes: 14
Reputation: 1856
You need to create at least one collection before it saves the database. Issuing a use will create it, but will not automatically save it. You can create an empty collection with db.createCollection("test"). To verify try the following commands from the mongo shell:
use mays
show dbs (mays will not show up)
db.createCollection("test")
show dbs (mays will show up)
Upvotes: 3