c# - 选择具有嵌入文档的过滤值的文档
问题描述
你能指导我如何使 C# 等效吗
db.UserProfile.aggregate([
{$match:{_id:"sen"}},
{
$project: {
DemRole: {
$filter: {
input: "$DemRole",
as: "item",
cond: { $eq: [ "$$item.Name", "CO" ] }
}
}
}
}
])
如果匹配_id,我正在尝试选择一个文档,并在对嵌入式文档应用过滤器后检索结果。它在 Robo3T 上的 MongoDB 中运行良好。但我无法在 C# 中翻译相同的内容。
解决方案
这应该可以帮助您:
var collection = new MongoClient().GetDatabase("test").GetCollection<User>("UserProfile");
var pipeline = collection.Aggregate()
.Match(up => up.Id == "sen")
.Project(up => new { DemRole = up.DemRole.Where(c => c.Name == "CO") });
推荐阅读
- vba - 无法使用 usedrange 属性创建循环
- azure - 可以删除 Azure 自动化作业输出
- python - 芹菜任务中的打印语句不起作用
- c - 按 TAB Linux C 程序显示可执行文件的名称
- html - 字体真棒包未在 Chrome 上加载
- javascript - 在 Array.filter 中使用 Set.has - 不兼容的接收器
- javascript - 你好,当我运行这段代码时,我一直不确定
- r - 使用 .csv 文件中的数据替换 .txt 文件中的单词
- java - alt 显示组合键但 ctrl 不显示
- angular - Angular 6英雄之旅教程-如何在HTTP post Observable函数中添加更多属性