IMongoDatabase.ListCollections
将光标移到BsonDocument
上。
为什么它不返回光标到IMongoCollection<T>
上?
我试图编写一个通用的GetCollection
方法来检索仅给出文档类型的集合,就像这样:
private IMongoCollection<T> GetCollection<T>()
{
var client = new MongoClient("connectionString");
var db = client.GetDatabase("dbName");
var coll = db.ListCollectionsAsync().Result.ToListAsync().Result
// Find collection of document of type T
// Collection is a BsonDocument instead
.Find(collection => typeof(collection) == typeof(T));
return coll;
}