//4b2 InsertOne 1 row document - bất đồng bộ Async
public string DocumentInsert_InsertOne_Async(string name = "honda v1")
{
new Task(() => { DocumentInsert_OneRow_Async2(); }).Start();
return "InsertOne complete"; ;
}
//4b2 insert 1 row document - bất đồng bộ Async
public async void DocumentInsert_OneRow_Async2()
{
// 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"
);
//lấy database
var database = client.GetDatabase("HvDadabase");
//Lấy List Collection
var collection = database.GetCollection<BsonDocument>("HvCars");
//select lấy 1 row Document
var document = new BsonDocument
{
{ "name", "vin v1" },
{ "year", 2001}
};
await collection.InsertOneAsync(document);
}
0 Nhận xét