How do I write this query on java api ? ',' means 'or' clause
db.questions.find( { user_id: /bc/ },{user_name:/bc/},{age:/2/} )
I've tried different ways, but I've been successful using one option only. How to add multiple options using "or" clause ?
here my code :
MongoClient mongoClient;
DB db;
DBCollection table;
DBCursor cursor = null;
mongoClient = new MongoClient("localhost", 27017);
db = mongoClient.getDB("stackoverflow");
boolean auth = db.authenticate("aku", "kamu".toCharArray());
table = db.getCollection("questions");
cursor = table.find(new BasicDBObject("user_id", java.util.regex.Pattern.compile("milk")));
while (cursor.hasNext()) {
DBObject object = cursor.next();%>
out.print(object.get("user_id"));
}
Using mySQL, the query is :
select * from questions where user_id like '%bc%' or user_name like %bc% or age like %2%
I'm new to mongoDB, I feel like it's fairly hard to convert queries from mySQL..
