Installing MongoDB and creating a database
In this section we shall install MongoDB and create a database:
- Download the MongoDB database at http://www.mongodb.org/downloads.
- Configure the data folder by executing the following command in the
binfolder:>mongod.exe -dbpath e:\mongodata\db - Start
mongod.exein another Command Prompt. - Execute the following command:
>show databaseExecuteThe
>show dbscommand also works fine with MongoDB. - Execute the following command to create a new database, namely
eshopdb.>use new-eshopdb - Executing
> show dbswill still show thateshopdbhasn't been created yet; this is because it doesn't contain any collections. Let's add some collections in the next step, once a collection is added. - Execute the following snippet in the Command Prompt. The following snippets will insert sample documents into the collection:
db.eshopdb.insert({cust_id:1,name:"kishore",address:"jayangar"}) db.eshopdb.insert({cust_id:2,name:"bapi",address:"HAL Layout"}) db.eshopdb.insert({cust_id:3,name:"srini",address:"abbigere street"}) db.eshopdb.insert({cust_id:4,name:"sangamesha",address: "Kattarigupee layout"})