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

后端 未结 3 2054
再見小時候
再見小時候 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 13:59

    The reason is you need to wait to get the store to create the document. In this case collection.InsertOneAsync(entity); the execution exit before creating the document.

    Either Console.ReadKey() or collection.InsertOneAsync(entiry).Wait() or any other form of stopping exit for a fraction of second will do the trick.

提交回复
热议问题