node.js - 如果第三个键为真,则比较 mongodb 文档的两个键
问题描述
我有这样的文件,我正在使用 mongo 3.6 和聚合。
[
{
id: 123,
isLimit: "YES",
maxUserCanComment: 10,
commentCount: 6
},
{
id: 124,
isLimit: "NO",
maxUserCanComment: 0,
commentCount: 3
},
{
id: 125,
isLimit: "YES",
maxUserCanComment: 3,
commentCount: 5
}
]
我需要那个文件,如果 isLimit == "NO" 拿它,如果 isLimit == "YES",首先检查commentCount < maxUserCanComment。我试过这个
[
$expr: { $gt: ["$commentCount", "$maxUserCanComment"] } // and also tried to add ithis in $cond
]
解决方案
推荐阅读
- php - 在 PHPSpreadhseet 中添加自定义字体
- kubernetes - 如何通过入口在具有相同主机的 Kubernetes 中公开多个应用程序
- java - 从邮递员 Spring Mvc 获取时未从 resttemplate.exchange 获取响应正文
- excel - 使用 VBA 将 vlookup 函数写入 Excel 单元格
- mysql - 在查询结果中使用 WHERE 条件作为列名
- laravel - 仅当删除缓存时,laravel 才在编辑后不显示新图像
- qt - mac菜单视图中的“隐藏标签栏”
- java - 手动将 java.sql.Timestamp 转换为 LocalDate 时的奇怪行为
- subquery - 带有偏移量 LIMIT 的慢 AQL 子查询
- angular - Angular Ngx-Bootstrap v.5.5.0 日期选择器