【发布时间】:2012-02-25 19:39:50
【问题描述】:
我开始在 C# 中使用 MongoDB,通过学习一些教程,我发现 Find & FindAll 方法在最新版本中不再存在。
有人能解释一下为什么以及我现在如何使用 v1.3.1 获得相同的功能吗?
【问题讨论】:
标签: mongodb mongodb-.net-driver mongo-collection
我开始在 C# 中使用 MongoDB,通过学习一些教程,我发现 Find & FindAll 方法在最新版本中不再存在。
有人能解释一下为什么以及我现在如何使用 v1.3.1 获得相同的功能吗?
【问题讨论】:
标签: mongodb mongodb-.net-driver mongo-collection
不,他们应该是。至少我在 git here 第 1655 行的 master 分支上看不到它们。在 1.3.1 here 的发行说明中,我也找不到任何重大更改。
您似乎找不到它们,因为您以与以前不同的方式创建了 mongodb 集合。基本上有两种方法:
第一种方法是在获取集合时指定文档的确切类型:
var collection = db.GetCollection<ICanSpecifyTypeHere>("name")
//then collection has Find and FindAll methods
var result = collection.Find(Query.And());
第二种方法是在 find 方法中指定文档类型:
var collection = db.GetCollection("name");
//in this case you should use FindAs<TypeOfDocument> and FindAllAs<TypeOfDocument>
var result = collection.FindAs<ICanSpecifyTypeHere>(Query.And());
我想您已经按照第二种方法声明了集合,因此看不到 Find 和 FindAll 方法。
【讨论】: