ext .: http://www.cnblogs.com/bjjjunjie/p/4076177.html
Now the development of this project to use MONGO database development, found that the online tutorial is relatively small, only to look at the official side of the development, the development process to write down notes, also counted is a summary of it.
I developed the use of vs2013, the driver is the latest 1.9.2 version of
Online connection Database Tutorial A lot of search, I will not repeat, only one to write a database connection method
1ProtectedvoidGetconnection ()2{34//Defining MONGO Services56 Mongoserver MONGO = Mongoserver.create (" connection string 7 8 // open connection 9 10 MONGO. Connect (); 11 12 // Get the database Cnblogs and automatically create 13 14 mongodatabase db = Mongo. Getdatabase ( "test") Span style= "color: #0000ff;" >as Mongodatabase; 16}
To find out is the bsondoucment type, at the beginning I was thinking, how and entity objects associated with it, went a lot of detours, and later looked at someone else's article only understand, originally found to set up when the support of generics, using generic set can be directly related to the object,
Mongocollection collection = db. Getcollection<user> ( "users" ); // Create an employee Chengji Chengji = new Chengji (); Chengji. Yuwen = 7489new User (); employee. Name = 798" ; Employee.chengji.Insert (Chengji); // write it into the upper set to collection. Insert (employee);
This will be able to insert user this entity object into the database, user is one of my entity class. A simple insert work is done.
Next I will focus on how to put the field is a collection collection of the class into the database, just in the actual project to use, but also hope that we have a lot of criticism.
C # Development MONGO notes first article