Create the database in MongoDB
1. Connect with MonoDB
Whenever 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
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.
>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:
-- Assign value to j
>j={name:"RAM"}
{"name" : "RAM" }
--Insert value into table employee
>db.employee.insert(j)
WriteResult({ "nInserted" : 1 })
-- Fire select query on employee table
>db.employee.find()
{ "_id" : ObjectId("540eb24efbf4b1a1447adde9"), "name" : "RAM" }
-- Check the databases
>show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
test (empty)