Create the database in MongoDB

Create the database in MongoDB

1. Connect with MonoDB
Whenever you connect with Mongodb, it will go to default test database

MongoDB shell version: 2.6.4
connecting to: test
> db

2. Display the list of databases

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

3. Switch to a new database named mydb

>use mydb
switched to db mydb

4. Check the database.


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.


-- Assign value to j
{"name" : "RAM" }

--Insert value into table employee
WriteResult({ "nInserted" : 1 })

-- Fire select query on employee table
{ "_id" : ObjectId("540eb24efbf4b1a1447adde9"), "name" : "RAM" }

-- Check the databases
>show dbs
admin  (empty)
local  0.078GB
mydb   0.078GB
test   (empty)

Leave a Reply

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

You are commenting using your 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.