In this article, we will learn how we can do the MongoDB basic integration with Visual Studio 2015.

First, we create a new project named “MongoDBTest” and we will choose console application as follows:


Now, we need to add the references for MongoDB. We can use the nuget package manager option.


Then, browse for “MongoDB” and install the following two references.



Now the application is well set for using mongodb. Let’s start coding…

First, we will create a domain class named “Employee” as follows:

Here, we use “[BsonId]” which is default ID property for mongodb and the “[BsonIgnoreIfNull]” token is for avoid the null value adding.


Second, we will create a Context class inside the program.cs class.

Here, we have the access of the “HR” database and we will do some actions in the “Employee” collections. Now,

Now, We will update or add records to our mongodb.

So, as we can see it is very easy to integrate the mongodb to visual studio. Make sure that your mongodb server is running. Now if you run the application then the following results can be found:


I hope you enjoyed this very simple mongodb integration with visual studio and c#. Click here to download the source.

Thank you


Leave a Reply