I was not very busy recently. I just wanted to play with nosql. After reading the MongoDB tutorial, I was attracted by its simplicity. So I couldn't help but want to write out the results of the morning search and share them with me, it's worth mentioning.
1) first install the MongoDB server. download it from here.
2) My system is win7 flagship, so the download is mongodb-win32-i386-1.9.0 this or non-stable version.
You can use commands to create a data file storage directory.
Do not close this window. If you close the window, you will understand it.
3) download the C # client here.
4) create a console project and add DLL reference (if the source code is below, you can add a new console project in the original solution and then add the project reference .)
Connect to the server
You can write the following code to connect to MongoDB:
In this way, the default host is localhost. If you want to use other hosts and ports, you can choose another reset method.
Obtain database instances
Here, we still need to create a database. You can use the getdatabase method to create and return the "mymongodb" database instance. The source code of getdatabase is as follows:
Refer to "table"
MongoDB does not have the concept of "Table". MongoDB regards all records as "document ". Replace familiar tables with document sets.
In this way, a set of documents named "Hello" is created.
Document recognition: Everything is a document
In the MongoDB world, you can use document to insert data, update data, and query data. The document is at the core here. Insert a helloword record first.
You can output records by traversing the document set.
I think MonoDB is worth it.
Reference: http://jasona.wordpress.com/2010/02/04/getting-started-with-mongodb-and-c/