How to insert data into a mongodb collection using the c# 2.0 driver?

后端 未结 3 2052
再見小時候
再見小時候 2020-12-16 13:25
  1. I\'m using the MongoClient in my c# console application to connect to MongoDB

https://github.com/mongodb/mongo-csharp-driver/releases/tag/v

3条回答
  •  眼角桃花
    2020-12-16 14:02

    for .net 4.5 and greater versions and mongodriver 2x series follow the below code

    var Client = new MongoClient();
    var MongoDB = Client.GetDatabase("shop");
    var Collec = MongoDB.GetCollection("computers");
    var documnt = new BsonDocument
    {
        {"Brand","Dell"},
        {"Price","400"},
        {"Ram","8GB"},
        {"HardDisk","1TB"},
        {"Screen","16inch"}
    };
    Collec.InsertOneAsync(documnt);
    Console.ReadLine();
    

提交回复
热议问题