【问题标题】:how to search in mongodb java with multiple conditions in where clause如何在where子句中使用多个条件在mongodb java中搜索
【发布时间】:2014-06-27 03:24:04
【问题描述】:
{
  "_id" : ObjectId("53ace08c98dea42bb1cb84ba"),
  "id" : "xyz",
}

选择id = "xyz"id = "abc" 所在的集合

如何用Java在mongodb中编写这个查询

【问题讨论】:

标签: java mongodb


【解决方案1】:

您可以通过使用 $or 操作数来使用 OR 子句来执行 mongodb 查询。

db.col.find({$or:[clause1, Clause2]})

DBObject document1 = new BasicDBObject("id", "abc");  
DBObject document2 = new BasicDBObject("id", "xyz");       

or.add(document1);
or.add(document2);

DBObject query = new BasicDBObject("$or", or);

DBCursor cur=db.getCollection("user").find(query);//user is the collection

while(cur.hasNext()){
System.out.println(cur.next());
}

你也可以通过这个链接How can I build an $or query for MongoDB using the Java driver?

【讨论】:

    猜你喜欢
    • 2018-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 2016-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多