c# - MongoDB C# CommandDocument 如何添加查询

标签 c# mongodb

如果 shell 中的命令是:

db.runCommand({"distinct":"log", "key":"cs_uri_stem"});

我发现相应的C#代码是:

var command = new CommandDocument { 
                                            { "distinct", "log" }, 
                                            { "key", "cs_uri_stem"},
                                    };

但是下面的命令怎么样?

db.runCommand({"distinct":"log", "key":"cs_uri_stem", query:{ datetime: { $gt: new ISODate("2012-07-05T19:55:18.475Z"), $lt:new ISODate("2012-07-05T20:55:18.475Z")} }})

我不知道如何在 C# 中做到这一点...

提前致谢!!

最佳答案

也在以下位置提问和回答:

https://groups.google.com/forum/?fromgroups#!topic/mongodb-user/TKZj_Qs0W5E

实际上,MongoCollection 中有一个可以使用的辅助方法。您的第二个不同的命令可以用 C# 编写,如下所示:

var collection = database.GetCollection("log");
var query = Query.And(
    Query.GT("datetime", new DateTime(2012, 7, 5, 19, 55, 18, 475, DateTimeKind.Utc)),
    Query.LT("datetime", new DateTime(2012, 7, 5, 20, 55, 18, 475, DateTimeKind.Utc))
);
var result = collection.Distinct("cs_uri_stem", query);
foreach (var distinctValue in result)
{
    // process distinctValue
}

关于c# - MongoDB C# CommandDocument 如何添加查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11354460/

相关文章:

c# - "switch"语句评估线程安全吗?

c# - 如何在 Asp.net 中获取 CheckBoxList 中的选定项

node.js - 跳过 Mongoose 中某些更新的时间戳中间件

mongodb - 是否可以在 MongoDB 数据库中的对象之间建立关系?

javascript - Mongoose ,从子文档中提取

c# - 从分数中设置高分并在unity2D游戏中显示

c# - 如何在 C# 中处理大文件?

mongodb - Mongo shell聚合查询问题

Mongodb通过对多个集合进行分组进行聚合查询

c# - System.EntryPointNotFoundException + 无法安装包 'SQLite.Interop.dll 1.0.103' 。我的项目目标'.NETFramework,Version=v4.6.1'