Introduction

In this article series we will analyse how to use Mongo DB in an ASP.NET MVC application. Mongo DB is from a family of emerging NoSQL databases. It is a database for information no longer stored in rows but rather in rich documents. Mongo db uses BSON that is very similar to JSON.

Using Mongo DB in MVC

The following explains why to use Mongo DB in MVC:

Mongo has Grid FS for storing querying and associating files with data in our applications.

We will learn the following things in this article series:

Documents in Mongo DB

Documents are a set of name/value pairs, also known as key value pairs. In the driver these are refered to as elements. In the preceding document customer id 1234 is an example of an element with the name of customer id and a value of 1234.and the payment is an embedded document and also a value can be an array.

Let's experiment with the BSON document in the following Test Project.

MongoTests class

Create a class named MongoTests as in the following:

  1. using System;
  2. using MongoDB.Bson;
  3. using NUnit.Framework;
  4. namespace MongoTests
  5. {
  6. public class BsonDocumentTests
  7. {
  8. [Test]
  9. public void SampleEmptyDocument()
  10. {
  11. var document = new BsonDocument();
  12. Console.WriteLine(document);
  13. }
  14. }
  15. }
Create a class named

Now let's try to add some elements.

One way to add elements is through the add method. BSON also supports adding elements through C# collection initializes:

  1. [Test]
  2. public void AddElements()
  3. {
  4. var people = new BsonDocument {{"Name", new BsonString("sagar")}};
  5. Console.WriteLine(people);
  6. }
add some elements

Summary

In this article we have learned about Mongo db. Mongo Db is named as the best database management system of 2013 by db engine and is increasingly being added to job postings and desired skill sets. In my future articles we will see more on Mongo DB.