MongoDB Mongo CSHARP driver source code analysis (1)

Source: Internet
Author: User

MongoDB Mongo csharp driver: https://github.com/mongodb/mongo-csharp-driver/downloads

For details, visit the official MongoDB website.

The following example shows a simple query:

 //  Create a database connection. The default local connection port is 27017.  
Mongoserver Server = Login server. Create ();
// Obtain the database. If not, it is automatically created.
Relational Database = Server. getdatabase ( " Mydatabase " );
// Get collection set
Mongocollection things = Database. getcollection ( " Things " );
Try
{
// Open connection
Server. Connect ();
// Set the query condition X like (3, 4)
Queryconditionlist Condition = New Queryconditionlist ( " X " );
Condition. In ( New Bsonarray (). Add ( New Bsonint32 ( 3 ). Add ( New Bsonint32 ( 4 )));
Mongocursor < Bsondocument > Cur = Things. findas < Bsondocument > (Condition );
Foreach (Bsondocument item In Cur)
{
MessageBox. Show (item [ " J " ]. Asdouble. tostring ());
}
}
Finally
{
// Close connection
Server. Disconnect ();
}

In Mongo CSHARP driver, there are mainly driver and bson packages.In the above example, we use several classes

Mongoserver

Relational Database

Collections collection

Queryconditionlist

Mongocursors

In the future, we will first analyze these categories to implement database addition, deletion, modification, and query functions.

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.