C # Development MONGO notes first article

Source: Internet
Author: User

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

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.