Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't create mongodb db

Tags:

mongodb

ubuntu

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
like image 897
Jamie Hutber Avatar asked Sep 16 '15 21:09

Jamie Hutber


1 Answers

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.

like image 126
Suhas Shelar Avatar answered Nov 15 '22 04:11

Suhas Shelar