1
我對我收集運行這樣的聚集陣列蒙戈aggegation沒有結果
{
/* my thought's body */
"author" : [
{ /* my author's body */ }
]
}
有沒有得到任何可能導致相同的,但沒有「作者」字段中的數組 - 只是同一個對象?
我對我收集運行這樣的聚集陣列蒙戈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解構輸入文檔中的數組字段,爲每個元素輸出一個文檔。