当我们在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"]}'