//4b1 InsertOne 1 row document
public string DocumentInsert_InsertOne(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
//var document = new BsonDocument
//{
// { "student_id", 10000 },
// { "scores", new BsonArray
// {
// new BsonDocument{ {"type", "exam"}, {"score", 88.12334193287023 } },
// new BsonDocument{ {"type", "quiz"}, {"score", 74.92381029342834 } },
// new BsonDocument{ {"type", "homework"}, {"score", 89.97929384290324 } },
// }
// },
// { "class_id", 480}
//};
var document = new BsonDocument
{
{ "name", "Toyota v1" },
{ "year", 2001}
};
collection.InsertOne(document);
//await collection.InsertOneAsync(document);
re = "InsertOne complete";
return re;
}
0 Nhận xét