Check and create the database in MongoDB

Check and create the database in MongoDB

Whenenver you connect with Mongodb it will go to default test database

D:\mongodb\bin>mongo
MongoDB shell version: 2.6.4
connecting to: test
>
> db
test

Show dbs

Display the list of databases

> show dbs
admin  (empty)
local  0.078GB
test   (empty)

Switch to a new database named mydb

> use mydb

> use mydb
switched to db mydb
>

for check fire db

> db
mydb

Note: if you issue the show dbs operation again,it will not include the mydb database.
MongoDB will not permanently create a database until you insert data into that database.

Example:
——————–
> j={name:”RAM”}
{ “name” : “RAM” }

> db.employee.insert(j)
WriteResult({ “nInserted” : 1 })

> db.employee.find()
{ “_id” : ObjectId(“540eb24efbf4b1a1447adde9”), “name” : “RAM” }

> show dbs
admin  (empty)
local  0.078GB
mydb   0.078GB
test   (empty)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.