实现示例:
sql: state=11 and (aa=2 or bb=3)
mongodb: { state : “11” , $or : [ { aa : 2 } , { bb : 3 } ] }
BasicDBObject whereEnd = new BasicDBObject();
whereEnd.put(“status”, 11);
—————————————
or的方式1 (aa=2 or bb=3)
DBObject[] orList = new BasicDBObject[2];
orList[0] = new BasicDBObject(“aa”, 2);
orList[1] = new BasicDBObject(“bb”, 3);
—————————————-
or的方式2 (aa=2 or bb=3)
BasicDBList orList = new BasicDBList();
orList.add(new BasicDBObject(“aa”, 2));
orList.add(new BasicDBObject(“bb”, 3));
—————————————-
BasicDBList values = new BasicDBList();
values.add(new BasicDBObject(“$or”, orList));
whereEnd.put(“$and”, values);
=========================================