MongoDb is a scalable, high-performance, open source, document-oriented database written in C++.
From C#, it’s really easy to store your POCO objects as a document within Mongo. Internally to MongoDb stores documents as BSON (binary JSON) but as we’re using the C# MongoDb driver we can use our native POCOs.
Here's the simple POCO objects we'll be using:
It’s simple to connect to a database:
Here's an example of adding two asset documents:
To remove all the documents from a collection:
MongoDb is a free and open source project, to install simply download the binaries http://www.mongodb.org/downloads
Extract the binaries to C:\MongoDb, create a subfolder called Data then open command prompt and run the following command:
MongoDb is now running so we can interact with our database. Note: In production you can run MongoDb as a service using the “–service” switch.
You can download the source code from this sample here:
http://stevenhollidge.com/blog-source-code/MongoDbSample.zip
No comments:
Post a Comment