How to install mongodb and how it's work in Windows 7

Mongo DB installation and work out in Windows 7:
1.       Download the mongodb-win32-x86_64-3.0.7.zip and unzip the file and place the folder mongodb which is having the bin directory in the C:\ drive.
2.       In the C:\ drive make the directories C:\data\db for one instance of a database. Suppose if you want to make more than one database instance you have to make the directories as C:\data\db1 , C:\data\db2 and so on for any number of database instances.
3.       Open the command prompt (Run as Administrator)  and go to the location C:\mongodb\bin and run the command : C:\mongodb\bin>mongod.exe --dbpath C:\data\db. This will create a db instance with the default port 27017.
4.       If you want to create more than one db instance then you have to run
C:\mongodb\bin>mongod.exe --dbpath C:\data\db1 --port 27018
C:\mongodb\bin>mongod.exe --dbpath C:\data\db2 --port 27019
5.       Now for opening the client to access the created db instance(s) open the command prompt (Run as Administrator)  and go to the location C:\mongodb\bin and run the command : C:\mongodb\bin>mongo. This will open a client for the default port number 27017.
6.       If you want to connect to the other db instances then run the following:
C:\mongodb\bin>mongo --port 27018
C:\mongodb\bin>mongo --port 27019
7.       So in the opened client prompts run your json for MongoDB
8.       So first create a table schema like: Customer
9.       After than put JSON data in that table
Like: {
     "firstName": "John",
     "lastName": "Smith",
     "age": 25,
     "address":
     {
         "streetAddress": "21 2nd Street",
         "city": "New York",
         "state": "NY",
         "postalCode": "10021"
     },
     "phoneNumber":
     [
         {
           "type": "home",
           "number": "212 555-1234"
         },
         {
           "type": "fax",
           "number": "646 555-4567"
         }
     ]
 }

11.   For fetch the data from that table using this query
Like :   db.Customer.find({"firstName": "John"}).pretty()

12.   db.Customer.find().pretty()   for all data of this table


Previous
Next Post »