MongoDB (ii)

Source: Internet
Author: User

To manipulate a database through a program:

//Link String            stringConnectionString ="mongodb://192.168.1.107"; //Database name            stringDatabaseName ="LSQ"; //Collection Name            stringCollectionName ="mycollection"; //Defining MONGO ServicesMongo Mongo =NewMongo (connectionString); //gets the database that corresponds to DatabaseName, does not exist and is created automaticallyMongodatabase mongodatabase = MONGO. Getdatabase (DatabaseName) asmongodatabase; //gets the CollectionName corresponding collection, which does not exist and is automatically createdmongocollection<document> mongocollection = mongodatabase.getcollection<document> (collectionName) asMongocollection<document>; //Link DatabaseMongo. Connect ();
//defines a document object that is stored in a key-value pairDocument doc =NewDocument (); doc["ID"] =1; doc["MSG"] ="helloword!"; //insert this Document object into the collectionMongocollection.insert (DOC); //finds a Id=1 Document object in the collection for a key-value pairDocument DocFind = Mongocollection.findone (NewDocument {{"ID",1 } }); //The output finds the value of the key "MSG" in the Document object, and outputsConsole.WriteLine (Convert.ToString (docfind["ID"]+" "+docfind["MSG"])); Console.read ();

MongoDB (ii)

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.