gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:20:01 24 4
gpt4 key购买 nike

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

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" }
}
}
])

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

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

最佳答案

$unwind采用可选字段 preserveNullAndEmptyArrays默认情况下是 false .如果将其设置为 true,则 unwind 将输出为 null 的文档。 Read more about $unwind

{ 
"$unwind": {
path: "$fullMatches",
preserveNullAndEmptyArrays: true
}
},

关于sql - 如何在mongodb上检索空查找条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45088028/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com