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

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book