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
1 protected voidgetconnection ()2 {3 4 //Defining MONGO Services5 6Mongoserver MONGO = Mongoserver.create ("Connection String");7 8 //Open Connection9 Ten MONGO. Connect (); One A //get the database cnblogs and create it automatically if it doesn't exist - -Mongodatabase db = Mongo. Getdatabase ("Test") asmongodatabase; the -}
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 employeeChengji Chengji =NewChengji (); Chengji. Yuwen= About; Chengji. Shuxue= the; User Employee=NewUser (); Employee. Name="798"; Employee.chengji.Insert (Chengji); //write it down in the collection.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