1. 程式人生 > >mongo查詢or和like

mongo查詢or和like

select * from tb where time=XXX and (affectAreaCode like %1% or affectAreaCode like ‘%2%’…)

DBObject dbObject = new BasicDBObject();
String[] areaids = areaCode.split(",");
BasicDBList values = new BasicDBList();
for (String areaid : areaids) {
    Pattern pattern = Pattern.compile("^.*" + areaid + ".*$"
, Pattern.CASE_INSENSITIVE); values.add(new BasicDBObject("affectAreaCode", pattern)); } dbObject.put("$or", values);