1) and (with and when multiple conditions are met)
publicvoidtestAnd(){ new BasicDBObject(); //agender=‘female‘ AND age > 27 queryCondition.put("agender""female"); queryCondition.put("age"new BasicDBObject("$gt"27)); DBCursor dbCursor = coll.find(queryCondition); }
2) Or (two conditions satisfy one of them)
Public void Testorsinglefield() {DBObject querycondition =NewBasicdbobject ();//age<15 OR age>27Basicdblist values =NewBasicdblist (); Values.add (NewBasicdbobject ("Age",NewBasicdbobject ("$GT", -))); Values.add (NewBasicdbobject ("Age",NewBasicdbobject ("$lt", the))); Querycondition.put ("$or", values); Dbcursor dbcursor = Coll.find (querycondition); }
3) in (requires the value of a field in a range)
publicvoidtestIn(){ new BasicDBObject(); //age in [13, 47] new BasicDBList(); values.add(13); values.add(47); queryCondition.put("age"new BasicDBObject("$in", values)); DBCursor dbCursor = coll.find(queryCondition); }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The "MongoDB"-java implements the and, or, in operation of MongoDB