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 #