我有mongodb版本3.2.10与数据库名称“足球”和集合名称“足球运动员”。无法查询使用asp.net mongodb文档
这里是一个文件例如:
{ "_id" : ObjectId("58f2c4dfc9f8596b2e50c0c9"), "Name" : "Messi" }
我试图拉记录并显示在网页上,但我不能得到这个代码工作。 它返回错误
CS0411 The type arguments for method 'IMongoDatabase.GetCollection<TDocument>(string, MongoCollectionSettings)'
不能从使用推断。尝试明确指定类型参数。
代码:
using MongoDB.Bson;
using MongoDB.Driver;
protected void btnSave_Click(object sender, EventArgs e)
{
var connectionstring = "mongodb://localhost";
var client = new MongoClient(connectionstring);
var DB = client.GetDatabase("football");
var collection = DB.GetCollection("Footballers");
Response.Write(DB.GetCollection("Footballers"));
}
是一个错字'DB.GetCollection( “足球”)'? 'GetCollection'后面的点? – Veeram
@Veeram我在发布我的代码时发生了错误。我删除了。并且代码就是我正在尝试运行的结果,这是我在帖子中更新的错误消息。 – ikask