Reputation: 1631
How can I create the following query:
Name LIKE "ABC" or "DFG" in java driver for mongoDB?
I know that for creating regex without "or" I do it in this way:
BasicDBObject regexQuery = new BasicDBObject();
regexQuery.put("name",
new BasicDBObject("$regex", "ABC"));
Upvotes: 1
Views: 787
Reputation: 2599
The normal | operator works on mongo.
This should do:
BasicDBObject regexQuery = new BasicDBObject();
regexQuery.put("name",
new BasicDBObject("$regex", "ABC\\|DFG"));
If trying on mongo shell:
db.collection.find({name:/ABC|DFG/}).pretty()
Upvotes: 3