英文:
Mongo $match parent having a doubly nested array
问题
I'm trying to $match against Mongo elements for double nested array:
{
$match: {
"cards.[].listings.0": {
$exists: true,
},
},
},
I'm looking for parent documents which have "cards" which also have "listings".
我正在尝试针对双重嵌套数组在Mongo元素中进行匹配:
{
$match: {
"cards.[].listings.0": {
$exists: true,
},
},
},
我正在寻找具有"cards"并且也具有"listings"的父文档。
英文:
I'm trying to $match against Mongo elements for double nested array:
{
$match: {
"cards.[].listings.0": {
$exists: true,
},
},
},
I'm looking for parent documents which have cards which also have listings.
I've seen something like the above syntax before, although I'm not sure what this syntax is called or if it's possible to use it for double-nested arrays.
答案1
得分: 1
在聚合管道中,只需使用:
db.collection.aggregate([
{
$match: {
"cards.listings.0": {
$exists: true
}
}
}
])
查看在playground示例上的运行情况。
英文:
Inside an aggregation pipeline simply use:
db.collection.aggregate([
{
$match: {
"cards.listings.0": {
$exists: true
}
}
}
])
See how it works on the playground example
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论