//4b3 InsertMany row document
public string DocumentInsert_InsertMany(string name = "honda v1")
{
// Replace the uri string with your MongoDB deployment's connection string.
var client = new MongoClient(
"mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false"
);
string re = "";
//lấy database
var database = client.GetDatabase("HvDadabase");
//Lấy List Collection
var collection = database.GetCollection<BsonDocument>("HvCars");
//select lấy 1 row Document
List<BsonDocument> documentList = new List<BsonDocument>();
documentList.Add(new BsonDocument
{
{ "name", "Benz v1" },
{ "year", 2005}
});
documentList.Add(new BsonDocument
{
{ "name", "Benz v2" },
{ "year", 2006}
});
collection.InsertMany(documentList);
//await collection.InsertOneAsync(document);
re = "InsertMany complete";
return re;
}
0 Nhận xét