【发布时间】:2015-03-29 10:08:35
【问题描述】:
- 我在我的 c# 控制台应用程序中使用
MongoClient连接到 MongoDB
https://github.com/mongodb/mongo-csharp-driver/releases/tag/v2.0.0-rc0
-
我的代码
class Program { static void Main(string[] args) { const string connectionString = "mongodb://localhost:27017"; // Create a MongoClient object by using the connection string var client = new MongoClient(connectionString); //Use the MongoClient to access the server var database = client.GetDatabase("test"); var collection = database.GetCollection<Entity>("entities"); var entity = new Entity { Name = "Tom" }; collection.InsertOneAsync(entity); var id = entity._id; } } public class Entity { public ObjectId _id { get; set; } public string Name { get; set; } } -
成功运行上面的代码后,我无法使用这个命令在MongoDB数据库中找到这条记录:
db.entities.find().pretty()
我的代码有什么问题?
【问题讨论】:
标签: c# .net mongodb mongodb-.net-driver