Using Mongo DB in .Net

By Venkatesh Kumar Jul 20 2012
Using an open source database in .NET is not quite popular. In this blog, I am using Mongo DB in .Net. Here I explain the startup program and how we can connect with the Mongo DB in an ASP.NET application using .NET.
    • Like
    • Love It
    • Awesome
    • Interesting
    • It's Okay
    • Thumbs Down
  • 10.1k
  • 0

Here I am not going to explain about Mongo DB, but  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 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.

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.