Are mongodb ids unique ?

Why use MongoDB in MVC.Net?

“The MongoDB is now most popular cross platform NoSQL open source database management system. The MongoDB is written using the C++ language and developed by 10gen but now it's called MongoDB Inc.”


Now, coming back to the point, “Why use MongoDB in MVC?”. The main reason is to use MongoDB with ASP.Net MVC are,

1.      It is so Faster Development.
2.      It is so Minimal Migrations.
3.      It is much Easier Collaborations.
4.      It is so Maintainable Design.
5.      It is much Rich Behaviours.
6.      Scalability.
7.      GridFS

Example Source code for MongoDb with MVC 5 as,

using System;
using System.Web.Mvc;
using MongoDB.Driver;
using MongoDB.Bson;
namespace MongoDemoApp.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            MongoClient client = new MongoClient();
            //GET MONGO SERVER.
            var server = client.GetServer();

            ////GET MONGO DATABASE.
            var db = server.GetDatabase("MongoDemo");

            ////GET MONGO COLLECTION.
            var collection =   db.GetCollection("Users");

            ////ADD COLLECTION ROWS.
            collection.Save(new Users {
                    name ="Anil Singh",
                    site ="code-sample.com",
                    CretaeDate =DateTime.Now
            });

            //DROP COLLECTION
            //collection.Drop();
            return View(collection);
        }

        public class Users
        {
            public ObjectId id { get; set; }
            public string name { get; set; }
            public string site { get; set; }
            public DateTime CretaeDate { get; set; }
        }
    }
}

Result as,


I hope you are enjoying with this post! Please share with you friends. Thank you!!
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^