【问题标题】:Find & FindAll methods missing in MongoDB.Driver v1.3.1 for C#MongoDB.Driver v1.3.1 for C# 中缺少 Find 和 FindAll 方法
【发布时间】:2012-02-25 19:39:50
【问题描述】:

我开始在 C# 中使用 MongoDB,通过学习一些教程,我发现 Find & FindAll 方法在最新版本中不再存在。

有人能解释一下为什么以及我现在如何使用 v1.3.1 获得相同的功能吗?

【问题讨论】:

    标签: mongodb mongodb-.net-driver mongo-collection


    【解决方案1】:

    不,他们应该是。至少我在 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());
    

    我想您已经按照第二种方法声明了集合,因此看不到 FindFindAll 方法。

    【讨论】:

    • 谢谢。我会检查并回复您以将此标记为答案。
    • 我没有使用 var 声明我的变量。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2016-03-27
    • 2021-06-17
    • 2021-11-24
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 2023-01-27
    相关资源
    最近更新 更多