[英]Pass data from one $lookup to another
There is an aggregate request that includes two $lookups:有一个包含两个 $lookups 的聚合请求:
[{
$match: {
id
}
},
{
$lookup: { // 1
from: 'blogs',
as: 'blog',
pipeline: [{
$project: {
id: 1, // * From this
name: 1,
articles: 1
},
}, {
$match: {
articles: {
$in: [id]
}
}
}, {
$unset: 'articles'
}]
}
},
{
$lookup: { // 2
from: 'users',
as: 'user',
pipeline: [{
$project: {
id: 1,
user_name: 1,
picture: 1
},
}, {
$match: {
blogs: {
$in: [...] // To this
}
}
}]
}
}
]
How can you transfer a field from the first to the second (the field is marked with *
)?如何将字段从第一个转移到第二个(该字段标有*
)?
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet,consectetur adipiscing elit,sed 做 eiusmod tempor incididunt ut labore et dolore magna aliqua。
Use let: { "blogIds": "$blog.id" }
使用let: { "blogIds": "$blog.id" }
and in pipeline use $$blogIds
并在管道中使用$$blogIds
$lookup: {
from: 'users',
as: 'user',
let: { "blogIds": "$blog.id" }
pipeline: [{ ... }]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.