2
{
"_id" : 123,
"someKey" : "someValue",
"someArray" : [
{
"name" : "name1",
"someNestedArray" : [
{
"name" : "value_1",
"fame" : [
{
"goal" : "goal_1"
}
]
},
{
"name" : "value_2",
"fame" : [
{
"goal" : "goal_2"
}
]
}
]
}
]
}
我做了查询,如:提取特定元素MongoDB中的嵌套数组
db.getCollection('city').find({"someArray.0.someNestedArray.1.fame.0.goal":"goal_2"},{"someArray.0.someNestedArray.":1})
但得到的输出为:
{
"_id" : 123,
"someArray" : [
{}
]
}
是什么让输出作为查询:
{
"fame" : [
{
"goal" : "goal_2"
}
]
}
在此先感谢。 同时告诉如何在不知道索引时在嵌套数组中找到值。 我也做了查询指定数组元素的位置(someArray.0.someNestedArray.1.fame.0.goal)
检查[mongodb位置运算符](https://docs.mongodb.com/manual/reference/operator/update/positional/) –
位置$运算符不能用于遍历多个数组的查询,例如查询嵌套在其他数组中的遍历数组的查询,因为替换$ placeholder是单个值。 –