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);

猜你喜欢

转载自blog.csdn.net/jiangshuanshuan/article/details/81533029