C # Development MONGO notes first article

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.