{
"_id" : ObjectId("53ace08c98dea42bb1cb84ba"),
"id" : "xyz",
}
select this collection where id = "xyz"
or id = "abc"
how to write this query in mongodb by Java
{
"_id" : ObjectId("53ace08c98dea42bb1cb84ba"),
"id" : "xyz",
}
select this collection where id = "xyz"
or id = "abc"
how to write this query in mongodb by Java
You can use OR clause by using the $or operand to perform mongodb queries.
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());
}
You can go through this link too How can I build an $or query for MongoDB using the Java driver?