我有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