mongodb you can't add a second
问题信息:
Due to limitations of the com.mongodb.BasicDBObject, you can't add a second 'createTime' expression specified as 'createTime : { "$lt" : 1468339200000}'. Criteria already contains 'createTime : { "$gt" : 1468252800000}'.
------------------------之前代码----------------------------------------
if(endTime!=null){ endTime = DateUtil.getEndOfDay(endTime); } if (startTime !=null) { criteria.and("createTime").gte(startTime); } if(endTime!=null){ criteria.and("createTime").lte(endTime); }
------------------------修改代码----------------------------------------
if(endTime!=null){ endTime = DateUtil.getEndOfDay(endTime); } if (startTime !=null&&endTime==null) { criteria.and("createTime").gte(startTime); }else if(startTime==null&&endTime!=null){ criteria.and("createTime").lte(endTime); }else if(startTime!=null&&endTime!=null){ criteria.andOperator( Criteria.where("createTime").gte(startTime), Criteria.where("createTime").lte(endTime) ); }