嵌套对象上的投影 mongodb 查找查询
Projection on nested object mongodb find query
如何在 mongodb 查找查询中获取投影中的嵌套对象。
[
{
"apikey": 1,
"meta": {
"region": {
"country": "India",
"city": "bangalore",
"pincode": 560067
},
"address": {
"houseNo": "G/C 42 Whitefield boulavourd",
"landmark": "whitefield boulavourd"
}
}
},
{
"apikey": 2,
"meta": {
"region": {
"country": "Germaany",
"city": "Munich",
"pincode": 80297
},
"address": {
"houseNo": "Zweibrückenstraße 12",
"landmark": "Zweibrückenstraße 12"
}
}
}
]
我试图获取 apikey 2 的区域。我在下面尝试查找查询
我尝试查找查询,即
db.collection.find({
"apikey": "2"
},
{
"projection": {
"_id": 0,
"apikey": 1,
"meta.region": 1
}
})
我收到错误消息,关于无法在排除投影中对字段 meta.region
进行包含。
有没有其他方法可以解决这个问题。
我想要输出,
[
{
"apikey":2,
"region": {
"country": "Germaany",
"city": "Munich",
"pincode": 80297
}
}
]
删除 projection
(环绕)级别。
db.collection.find({
apikey: 2
},
{
"_id": 1,
"apikey": "$apikey",
"region": "$meta.region"
})
如何在 mongodb 查找查询中获取投影中的嵌套对象。
[
{
"apikey": 1,
"meta": {
"region": {
"country": "India",
"city": "bangalore",
"pincode": 560067
},
"address": {
"houseNo": "G/C 42 Whitefield boulavourd",
"landmark": "whitefield boulavourd"
}
}
},
{
"apikey": 2,
"meta": {
"region": {
"country": "Germaany",
"city": "Munich",
"pincode": 80297
},
"address": {
"houseNo": "Zweibrückenstraße 12",
"landmark": "Zweibrückenstraße 12"
}
}
}
]
我试图获取 apikey 2 的区域。我在下面尝试查找查询 我尝试查找查询,即
db.collection.find({
"apikey": "2"
},
{
"projection": {
"_id": 0,
"apikey": 1,
"meta.region": 1
}
})
我收到错误消息,关于无法在排除投影中对字段 meta.region
进行包含。
有没有其他方法可以解决这个问题。
我想要输出,
[
{
"apikey":2,
"region": {
"country": "Germaany",
"city": "Munich",
"pincode": 80297
}
}
]
删除 projection
(环绕)级别。
db.collection.find({
apikey: 2
},
{
"_id": 1,
"apikey": "$apikey",
"region": "$meta.region"
})