我使用 c# mongodb 驱动程序进行查询。如果我使用 db.GetCollection.Distinct()
函数,然后调用 MongoCursor collection.FindAs(query)
,我会得到一个错误:'System.Collections.Generic.IEnumerable<applition>' does not contain a definition for 'FindAs' and no extension method 'FindAs' accepting a first argument of type 'System.Collections.Generic.IEnumerable<application>' could be found.
有谁知道在使用 mongodb 游标和 IMongoQuery 的情况下如何调用不同的函数?提前谢谢你。
最佳答案
我已经使用 runCommand 方法完成了预期的结果。 我有一个名为“capped”的系列。其中包含名为“x”的字段的记录。我在集合中插入了不同的值,其中有多个值27。 下面的 Javascript 语句说:“我希望集合中的不同值在 distinc 键是名为 'x' 的列中设置上限,并且我正在查询 x 为 27 的值”。
在 Javascript 中,它看起来像这样:
db.runCommand({ "distinct":"capped", "query" : { "x" : 27 }, "key":"x" });
在 C# 中,它看起来有些相似:
CommandDocument distinctCmd = new CommandDocument{ {"distinct", "capped"}, {"query", new BsonDocument("x", 27)}, {"key", "x"} }; CommandResult r = database.RunCommand(distinctCmd);
关于c# - 如何使用 c# MongoCursor 获取不同的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24873627/