[英]How to specify Multiple conditions in Java Mongo
I have a code which requires me to get user details from a mongo database collection 我有一个代码,要求我从mongo数据库集合中获取用户详细信息
Following is one of the field in my Users collection 以下是我的用户集合中的字段之一
"emailSettings" : {
"flag1" : true,
"flag2" : true,
"flag3" : true,
},
I'm parsing the Mongo collection from my java program using the BasicDB
object and I would want to get all the entries which satisfy the emailSettings.flag1 =true
and emailSettings.flag2 = true
. 我正在使用BasicDB
对象从Java程序解析Mongo集合,我想获取所有满足emailSettings.flag1 =true
和emailSettings.flag2 = true
的条目。
When I use BasicDBObject
to do this, I'm able to get entries satisfying only one of the conditions. 当我使用BasicDBObject
进行此操作时,我只能获得满足以下条件之一的条目。
Is there a solution for this ? 有解决方案吗?
In Mongo query parts are combined with 'and' operator by default. 在Mongo中,查询部分默认情况下与'and'运算符组合。 So simply doing this 所以只需这样做
DBObject query = BasicDBObjectBuilder.start("emailSettings.flag1", true).add("emailSettings.flag2", true).get();
should give you expected result. 应该给您预期的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.