如何在mongodb上检索空查找条目?

Lui*_*ulo 5 sql mongodb robo3t

我有这个查询,它为我提供了我想要的连接:

db.summoners.aggregate([
    { "$match": { "nick":"Luispfj" } },
    { "$unwind": "$matches" },
    {
        "$lookup": {
            "from":"matches",
            "localField":"matches.gameId",
            "foreignField":"gameId",
            "as":"fullMatches"
        }
    },
    { "$unwind": "$fullMatches" },
    {
        "$group": {
            "_id": null,
            "matches": { "$push":"$fullMatches" }
        }
    }
])
Run Code Online (Sandbox Code Playgroud)

但是当我运行 unwind 函数时,空条目消失了。我如何检索它们(如果可能,使用它们各自的“gameId”?

另外,有没有办法只检索matches数组,而不是它创建的“null-id-object”的子属性?

Ere*_*ald 8

$unwind采用一个可选字段preserveNullAndEmptyArrays,默认情况下为false. 如果将其设置为 true,则 unwind 将输出为 null 的文档。阅读有关 $unwind 的更多信息

{ 
  "$unwind": {
    path: "$fullMatches",
    preserveNullAndEmptyArrays: true
  }
},
Run Code Online (Sandbox Code Playgroud)