Reputation: 21295
I will be moving my web apps to MongoDB and I'm trying to get a feel of "the right way" of using MongoDB C# driver in my C# code.
I'm coming from MS SQL world where I am using stored procs only when dealing with SQL Server for the following reasons:
SQL code is completely separated from C# code
Easy to setup SQL access security (you do it on stored proc level)
SQL logic is separate from C# logic completely.
For those same reasons I have never used EF or LinqToSQL.
Following are some things that I'm trying to understand before I roll teh sleeves and start code migration:
Do I need to use some kind of wrapper (I am using a home-made OR wrapper between my middle tier and low level ADO.NET calls to stored procs; the wrapper creates C# functions which internally call SP's)
Should I use MongoDB's js server-side methods in leu of stored procs - again, to separate sql logic from c# code logic or shoudl I move all logic to C# and just do simple inserts/updates to MongoDB
Any other recommendations of correctly programming my applications for use with MongoDB
Upvotes: 2
Views: 1771
Reputation: 12187
The normal way CRUD operations are handled using the C# driver for MongoDB is to use the Insert, Find, Update and Remove methods of MongoCollection. There is also a Save method that calls Insert for a new document and Update for an existing document.
The documents themselves can either be instances of BsonDocument if you wish to work at a fairly low level, or instances of your own C# classes if you wish to create classes for your domain model. The C# driver can handle mapping C# classes to and from BSON documents.
With MongoDB you rarely use any Javascript server side, so there really is no need for anything equivalent to your SQL stored procs. You just do everything in C#.
You might decide to create a data access layer, but it will be much thinner than anything you might have used with SQL Server because the C# driver handles the mapping between objects and BSON documents.
Upvotes: 4