這是我的連接字符串到我的數據庫:MongoDB MongoClient.GetServer()已棄用。什麼是新的API?
private static string ConnectionString = "mongodb://user:[email protected]:port/";
private static string AuthSource = "?authSource=location";
public static MongoCollection<ItemEntity> GetMyItemCollectionDB = new MongoClient(ConnectionString + DBName + AuthSource)
.GetServer().GetDatabase(DBName).GetCollection<ItemEntity>(CollectionName);
我聽說你可以刪除getserver
方法:
public static MongoCollection<ItemEntity> GetMyItemCollectionDB = new MongoClient(ConnectionString + DBName + AuthSource)
.GetDatabase(DBName)
.GetCollection<ItemEntity>(CollectionName) as MongoCollection<ItemEntity>;
但是,我得到一個「空對象」的錯誤。有什麼問題?
編輯:如果使用新API沒有那麼重要,那就告訴我。
你的GetMyItemCollectionDB方法做了很多....哪一位返回null – Alex
那麼,第一個工程..我不明白爲什麼第二個不工作。你能解釋爲什麼嗎?和可能的解決方案 – Earlee