Pages

Saturday, June 9, 2012

Using Mongo DB in .Net


Here I am not going to explain about Mongo DB, but i just try to use Mongo DB in .Net.
By default, MongoDB wants to store data in the default file system path, c:\data\db.but this is configurable with a text file passed by name on the command line via --config.




 If you got the below error.  Just run the below mentioned command.
Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
Command:  mongod --dbpath "c://data/db"
Once configured the Mongo DB, we will install C# driver or we can use the NuGet package.
 http://www.nuget.org/List/Packages/mongocsharpdriver
After install the driver, add reference dll’s as mentioned below.
 
We will go through the sample application to use Mongo DB in .Net:
Just like SQL Server we need to create connection instance to the Mongo DB server.
Once the Db will be created we can able to go and check the db folder “\data\db” and the final thing is we can able to  add and query the data like sql.
Check the SQL to Mongo Mapping chart:
We execute the select query (.Find), get the data.