检索值:Meteor.js +的MongoDB ::从深度嵌套阵列
{
"_id" : "axHqB4NjXbWwphik3",
"name" : "Soda Rock",
"storeLocation" : [
{
"state" : "Victoria",
"outlet" : [
{
"city" : "Melbourne",
"name" : ["Chadstone", "South Yarra"]
},
{
"city" : "Geelong",
"name" : ["Myer", "Market Square"]
}
]
},
{
"state" : "New South Wales",
"outlet" : [
{
"city" : "Sydney",
"name" : ["Westfield", "Broadway Shopping Centre"]
}
]
}
]
}
我试过一些方法,但没有输出我想要的结果。
方法#1:
Stores.find(
{
'name': 'Soda Rock',
'storeLocation.outlet.city': 'Melbourne'
},
{
_id: 0,
'storeLocation.outlet.name.$': 1
}
);
结果:
{
"storeLocation" : [
{
"state" : "Victoria",
"outlet" : [
{
"city" : "Melbourne",
"name" : ["Chadstone", "South Yarra"]
},
{
"city" : "Geelong",
"name" : ["Myer", "Market Square"]
}
]
}
]
}
方法#2:
Stores.find(
{
'name': 'Soda Rock',
'storeLocation.outlet.city': {
'Melbourne'
}
},
{
_id: 0,
'storeLocation.outlet.name': 1
}
);
结果:
{
"storeLocation" : [
{
"outlet" : [
{
"name" : ["Chadstone", "South Yarra"]
},
{
"name" : ["Myer", "Market Square"]
}
]
},
{
"outlet" : [
{
"name" : ["Westfield", "Broadway Shopping Centre"]
}
]
}
]
}
我也曾尝试使用meteorhacks:aggregate,但无法使其工作,因为我没有找到一个新手友好的文档。
您的解决方案和友好的解释非常感谢!
这是一个非常紧凑的解决方案,而不是我试图过滤数据的方法。谢谢! – kyooriouskoala