java实现如下条件的mongodb查询
**用java操作,
条件:keyID=111111111111且point=A的所有record
这里的point是在remark里面的,而且只显示point=A和相应的city,其它的B,C都不要**
{
"tempList": [
{
"_id": ObjectId("5a6afcfce9ec67213fca393d8"),
"keyID": "111111111111",
"price": 123,
"remark": [
{
"city": "beijing",
"point": "A"
},
{
"city": "shanghai",
"point": "A"
},
{
"city": "guangzhou",
"point": "C"
}
]
},
{
"_id": ObjectId("5a6afcfce2121fca393d8"),
"keyID": "111111111111",
"price": 456,
"remark": [
{
"city": "beijing",
"point": "A"
},
{
"city": "shanghai",
"point": "B"
},
{
"city": "guangzhou",
"point": "C"
}
]
},
{
"_id": ObjectId("5a6afcfce9e32577223d8"),
"keyID": "222222222222",
"price": 789,
"remark": [
{
"city": "beijing",
"point": "A"
},
{
"city": "shanghai",
"point": "B"
},
{
"city": "guangzhou",
"point": "C"
}
]
}
]
}
----------------------------查询结果应该如下---------------------------
{
"tempList": [
{
"_id": ObjectId("5a6afcfce9ec67213fca393d8"),
"keyID": "111111111111",
"price": 123,
"remark": [
{
"city": "beijing",
"point": "A"
},
{
"city": "shanghai",
"point": "A"
}
]
},
{
"_id": ObjectId("5a6afcfce2121fca393d8"),
"keyID": "111111111111",
"price": 456,
"remark": [
{
"city": "beijing",
"point": "A"
}
]
}
]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$map,$reduce,$filter (segmentfault无法正确转义美元符号,凑合看吧……)这些运算符在很多场景下可以帮助我们避免$unwind,语法请参考下文档。对于你的要求,可以用
$filter
直接解决问题:文档格式:
aggregation写法: