遇到的问题-----you can't add a second 'treePath' criteria. Query already contains


当我们在java中使用mongo的spring接口进行查询时,如果需要对同一个字段  有两个限制条件,使用不当是则会报错:

例如 如下用法:


Criteria.where("treePath").in(parentId).and("treePath").size(level)


treePath有两个限制条件


报错:

org.springframework.data.mongodb.InvalidMongoDbApiUsageException: Due to limitations of the com.mongodb.BasicDBObject, you can't add a second 'treePath' expression specified as 'treePath : { "$size" : 2}'. Criteria already contains 'treePath : { "$in" : [ "50137df5f49f9b4a6481d639"]}'.<

已标记关键词 清除标记
相关推荐
这是代码区域 public List<HomeDeviceLog> selecVillageBuildingIntercom(Map<String, Object> maps) { List<Map<String, Object>> arrayList=propertyMapper.selecVillageBuildingIntercom(maps); Criteria criatira = new Criteria(); for (int i = 0; i < arrayList.size(); i++) { if(i==0){ criatira.andOperator(Criteria.where("gatewayId").is(arrayList.get(i).get("gateway_id")).and("deviceId").is(arrayList.get(i).get("device_id"))); } if(i>0){ criatira.orOperator(Criteria.where("gatewayId").is(arrayList.get(i).get("gateway_id"))); criatira.orOperator(Criteria.where("deviceId").is(arrayList.get(i).get("device_id"))); } } Query query = new Query(criatira); query.with(new Sort(Direction.DESC, "createdTime")); long totalCount = this.mongoTemplate.count(query, HomeDeviceLog.class); Pagination<HomeDeviceLog> page = new Pagination<HomeDeviceLog>(Integer.parseInt(maps.get("pageNum").toString()), Integer.parseInt(maps.get("pageSize").toString()), totalCount); query.skip(page.getFirstResult());// skip相当于从那条记录开始 query.limit(Integer.parseInt(maps.get("pageSize").toString()));// 从skip开始,取多少条记录 List<HomeDeviceLog> datas = mongoTemplate.find(query, HomeDeviceLog.class); for (int i = 0; i < arrayList.size(); i++) { for (int j = 0; j < datas.size(); j++) { if(arrayList.get(i).get("gatewayId").equals(datas.get(j).getGatewayId())&amp;&amp;arrayList.get(i).get("device_id").equals(datas.get(j).getDeviceId())){ datas.get(j).setAliases_name(arrayList.get(i).get("aliases_name").toString()); datas.get(j).setHomeName(arrayList.get(i).get("home_name").toString()); } } } return datas; } 错误异常 Due to limitations of the com.mongodb.BasicDBObject, you can't add a second '$or' expression specified as '$or : [ { "deviceId" : 3212929}]'. Criteria already contains '$or : [ { "gatewayId" : 327952}]'.
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页
实付 19.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值