Tags

, , , , , ,

If you have downloaded and installed mongoDB on your system (I preferred the instal location as C:\mongoDB) and finding trouble to connect to mongo database server at default port 27017, please do the following.

The rule that allows all incoming traffic to port 27017, which allows the application server to connect to the mongod.exe instance, is as follows:

Open CMD command promt as Admin and type..

> netsh advfirewall firewall add rule name=”Open mongod port 27017″ dir=in action=allow protocol=TCP localport=27017

Hit enter key and then type..

> netsh advfirewall firewall add rule name=”Allowing mongod” dir=in action=allow program=” C:\mongodb\bin\mongod.exe”

and Hit enter key.

You can also allow all access for a mongos.exe server, by typing the following at command prompt:

> netsh advfirewall firewall add rule name=”Allowing mongos” dir=in action=allow program=” C:\mongodb\bin\mongos.exe”

Having completed the above actions, now you should also complete the following steps one by one….

Open CMD command promt as Admin and create directory:

> mkdir c:\mongo\data\db

As Admin, install service:

> C:\mongodb\bin\mongod.exe –install –logpath c:\mongo\logs –logappend –bind_ip 127.0.0.1 –dbpath c:\mongo\data\db –directoryperdb

Now, Start MongoDB:

> net start MongoDB

Start Mongo Shell:

> C:\mongodb\bin\mongo.exe

This will start the database server.

 

To test if mongo database server is working, type at the shell:

> for (var i = 1; i <= 25; i++) db.testData.insert( { x : i } )

and hit enter

Again type:

> db.testData.find()

and hit enter

The mongo shell displays the first 20 documents in the collection. Your ObjectId values will be different:

{ “_id” : ObjectId(“51a7dc7b2cacf40b79990be6”), “x” : 1 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990be7”), “x” : 2 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990be8”), “x” : 3 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990be9”), “x” : 4 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bea”), “x” : 5 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990beb”), “x” : 6 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bec”), “x” : 7 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bed”), “x” : 8 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bee”), “x” : 9 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bef”), “x” : 10 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bf0”), “x” : 11 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bf1”), “x” : 12 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bf2”), “x” : 13 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bf3”), “x” : 14 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bf4”), “x” : 15 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bf5”), “x” : 16 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bf6”), “x” : 17 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bf7”), “x” : 18 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bf8”), “x” : 19 }
{ “_id” : ObjectId(“51a7dc7b2cacf40b79990bf9”), “x” : 20 }

Advertisements