MongoDB's C#and.net Driver

Source: Internet
Author: User

Previously used Nodejs to connect the operation MongoDB, but recently need to use C # to operate MongoDB needs, so the next C # driver research. MongoDB officially provides C # driver source Https://github.com/mongodb/mongo-csharp-driver on GitHub. Source download good after compiling get MongoDB.Bson.dll and MongoDB.Driver.dll two files, I have compiled the Http://yunpan.cn/QCFn3v86KaEST access password F0ef.

Add two files to the project reference and then add the appropriate using statements to the program. Then do a simple operation on it:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingMongodb.bson;usingMongodb.driver;namespacemongodbdriverlearn{classProgram {Static voidMain (string[] args) {            varClient =NewMongoclient ("Mongodb://sa:[email protected]:27017"); varServer =client.            Getserver (); varDatabase = Server. Getdatabase ("Demodatabase"); varCollection = database. GetCollection ("democollection"); Collection. Insert (NewBsondocument ("Name","Jack")); foreach(varDocumentinchcollection. FindAll ()) {Console.WriteLine (document["Name"]);        } console.read (); }    }}

 

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.