Simple example of MongoDB using 1.7 version-driven operation in C #

Source: Internet
Author: User


The code is as follows:


Create a database link

In version 1.7 of the driver, this will be reported that the Mongoserver method is outdated

Mongoserver Server = MongoDB.Driver.MongoServer.Create (strconn);


With the user name, password The following wording, without the direct ip+ port can be

Const string connectionString = "Mongodb://city:[email protected]:27017";

Get a reference to a client object Getserver () a reference to a server object

var Server = new Mongoclient (connectionString). Getserver ();

A reference to a database object

var client = server.getdatabase ("city");

A reference to a group of objects

var collection = client. Getcollection<citys> ("Citys");

Insert an Entity

for (int i = 0; i < dt. Rows.Count; i++)

{

Collection. Insert (New Citys

{

province = dt. Rows[i][0]. ToString (),

City = dt. ROWS[I][1]. ToString (),

County = dt. ROWS[I][2]. ToString (),

AreaCode = "0" + dt. ROWS[I][3]. ToString (),

PostalCode = dt. ROWS[I][3]. ToString ()

});

}

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
Simple example of MongoDB using 1.7 version-driven operation in C #

This address: http://www.paobuke.com/develop/c-develop/pbk23219.html






Related content JSON action Library Dynamicjson Use Guide C # Implement a complete example of a hook class that captures almost all keyboard and mouse events C # design Pattern Series Tutorial-abstract Factory mode Basic example of implementing TCP and UDP protocol-based network communication programs using C #
How C # automatically chooses the most appropriate IP address in the system C # Implement a method of using generics to convert a dataset to model how to implement the polymorphic phenomenon and polymorphism in C # method for uploading files with jquery in C #

Simple example of MongoDB using 1.7 version-driven operation in C #

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.