Blog

Using Mongo DB in .Net

Posted by Venkatesh Kumar Blogs | Databases & DBA 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.

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 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.


MongoDB.Bson

MongoDB.Driver

 

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.

COMMENT USING
PREMIUM SPONSORS
Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.