没有结果
问题描述:
我对我收集运行这样的聚集阵列蒙戈aggegation没有结果
{
/* my thought's body */
"author" : [
{ /* my author's body */ }
]
}
有没有得到任何可能导致相同的,但没有“作者”字段中的数组 - 只是同一个对象?
答
试试这个。
db.getCollection('thoughts').aggregate([
{
$lookup: {
from: "users",
localField: "author_id",
foreignField: "_id",
as: "author"
}
},
{"$unwind": "$author"}
])
$ unwind解构输入文档中的数组字段,为每个元素输出一个文档。