- 我正在使用c#console应用程序中的
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()
我的代码怎么了?