【发布时间】:2019-01-05 19:01:33
【问题描述】:
我想 $lookup 查找远程集合,例如 SQL Join,但使用 Mongo。而且我不希望远程文档中的所有键都被拉到源集合中 - 只是一些特定的键。
这是我尝试过的:
[
{
$lookup: {
from: "tables",
localField: "type",
foreignField: "_id",
as: "type"
}
},
{
$unwind: "$type"
},
},
{
$project: {
"type.title": 1
}
}
]
但是,这仅打印“type.title”并忽略所有其他键,即使来自原始文档。
有没有办法告诉 MongoDB 只从远程集合中提取特定字段?
【问题讨论】:
标签: database mongodb mongodb-query aggregation-framework