you can’t add a second ‘$and’
2016-01-24 21:00
316 查看
出现这样的错,说明你的程序在生成mongo语句的时候出现了两个and操作,那么这样的问题怎么解决呢!
List<Criteria> criteriaList = MongoUtils.buildCriteriaList(map);
Date startDate =null;
Date endDate =null;
if(followAnalizeQuery.getUrgeStartDate()!=null&&followAnalizeQuery.getUrgeEndDate()!=null){
startDate = DateUtil.parseDate(DateUtil.formatDate(followAnalizeQuery.getUrgeStartDate()));
endDate = DateUtil.parseDate(DateUtil.formatDate(followAnalizeQuery.getUrgeEndDate()));
Long time = endDate.getTime()+ONE_DAY;
endDate = new Date(time);
criteriaList.add(Criteria.where(URGE_TIME).gte(startDate).lt(endDate));
}else if(followAnalizeQuery.getUrgeStartDate()!=null){
startDate = DateUtil.parseDate(DateUtil.formatDate(followAnalizeQuery.getUrgeStartDate()));
criteriaList.add(Criteria.where(URGE_TIME).gte(startDate));
}else if(followAnalizeQuery.getUrgeEndDate()!=null){
endDate = DateUtil.parseDate(DateUtil.formatDate(followAnalizeQuery.getUrgeEndDate()));
Long time = endDate.getTime()+ONE_DAY;
endDate = new Date(time);
criteriaList.add(Criteria.where(URGE_TIME).lt(endDate));
}
String collectionName = mongoTemplate.getCollectionName(UrgeRecord.class);
GroupBy groupBy = GroupBy.keyFunction(followAnalizePageKeyFunction);
groupBy.initialDocument(followAnalizePageInitial);
groupBy.reduceFunction(getMongoSQL(connectStatus,unConnectStatus));
GroupByResults<FollowAnalize> groupResult=mongoTemplate.group(new Criteria().andOperator(criteriaList.toArray(new Criteria[criteriaList.size()])), collectionName, groupBy, FollowAnalize.class);
上面的代码是我重新改装后的,大意是将所有的And操作都放在List<Criteria>中,最后用new Criteria().andOperator(criteriaList.toArray(new Criteria[criteriaList.size()])将所有的and操作用一个and来完成,这样生成的语句中就只有一个and;
这样的问题我在本地也没有出现,但是在linux环境下就会出现
List<Criteria> criteriaList = MongoUtils.buildCriteriaList(map);
Date startDate =null;
Date endDate =null;
if(followAnalizeQuery.getUrgeStartDate()!=null&&followAnalizeQuery.getUrgeEndDate()!=null){
startDate = DateUtil.parseDate(DateUtil.formatDate(followAnalizeQuery.getUrgeStartDate()));
endDate = DateUtil.parseDate(DateUtil.formatDate(followAnalizeQuery.getUrgeEndDate()));
Long time = endDate.getTime()+ONE_DAY;
endDate = new Date(time);
criteriaList.add(Criteria.where(URGE_TIME).gte(startDate).lt(endDate));
}else if(followAnalizeQuery.getUrgeStartDate()!=null){
startDate = DateUtil.parseDate(DateUtil.formatDate(followAnalizeQuery.getUrgeStartDate()));
criteriaList.add(Criteria.where(URGE_TIME).gte(startDate));
}else if(followAnalizeQuery.getUrgeEndDate()!=null){
endDate = DateUtil.parseDate(DateUtil.formatDate(followAnalizeQuery.getUrgeEndDate()));
Long time = endDate.getTime()+ONE_DAY;
endDate = new Date(time);
criteriaList.add(Criteria.where(URGE_TIME).lt(endDate));
}
String collectionName = mongoTemplate.getCollectionName(UrgeRecord.class);
GroupBy groupBy = GroupBy.keyFunction(followAnalizePageKeyFunction);
groupBy.initialDocument(followAnalizePageInitial);
groupBy.reduceFunction(getMongoSQL(connectStatus,unConnectStatus));
GroupByResults<FollowAnalize> groupResult=mongoTemplate.group(new Criteria().andOperator(criteriaList.toArray(new Criteria[criteriaList.size()])), collectionName, groupBy, FollowAnalize.class);
上面的代码是我重新改装后的,大意是将所有的And操作都放在List<Criteria>中,最后用new Criteria().andOperator(criteriaList.toArray(new Criteria[criteriaList.size()])将所有的and操作用一个and来完成,这样生成的语句中就只有一个and;
这样的问题我在本地也没有出现,但是在linux环境下就会出现
相关文章推荐
- Varnish Install And Configure
- Insert Date and Time into Access
- asp的SQL语句中and和or同时使用的注意事项
- 拖动Html元素集合 Drag and Drop any item
- 学习drag and drop js实现代码经典之作
- And,Where使用提示以及用+进行左关联的提示及注意事项
- Android开发adb.exe' and can be executed.错误解决方法
- Table ‘xxx’ is marked as crashed and should be repaired 错误解决方法参考
- drag-and-drop实现图片浏览器预览
- python关键字and和or用法实例
- Python and、or以及and-or语法总结
- Python中AND、OR的一个使用小技巧
- Nginx中IF、AND、OR语句用法实例
- 负载均衡及会话保存(Ofbiz框架)
- Multithreading and Synchronization
- Due Care and Due Diligence
- DAS, NAS, and SAN
- Security Descriptors and Access Control Lists Tools and Settings
- 常用的Net Command
- makefile.in and makefile.am