mongodb - 如何在 MongoDB 中加入具有主条件的主从表
问题描述
如何为此查询添加 xads 条件?(Exp: lads.status=1 )
db.xads.aggregate([
{
$lookup: {
from: 'xaditems',
localField: '_id',
foreignField: 'masterId',
as: 'xadItems'
},
}
]);
解决方案
db.xads.aggregate([
{
$match:{"status":1} //add you filters in match
},
{
$lookup: {
from: 'xaditems',
localField: '_id',
foreignField: 'masterId',
as: 'xadItems'
},
}
]);
推荐阅读
- django - Django - 密码字段上的“此字段是必需的”错误
- multithreading - 设置要在 Julia Pro 中手动使用的线程数
- regex - 正则表达式 RE2:提取字符串末尾括号内的文本,包括括号,如果有多个,则仅提取最后一组
- typescript - 零个或所有可选但类型化的参数
- r - 用于汇总贷款数量的 R 函数
- mysql - 如何在mysql中正确利用索引的力量
- batch-file - findstr "^" 不起作用,但 "^^" 可以查找开始行
- r - 在 data.table 中描述 .SD 和 .SDcols 的更好方法是什么?
- c# - Unity 2D 中 Pixel Perfect Camera 和 Cinemachine 的问题
- node.js - 为什么一个 npm 模块会删除其他 npm 模块?