Criteria already contains 'xxx :

  • mongodb查询报错详情如下:
org.springframework.data.mongodb.InvalidMongoDbApiUsageException: Due to limitations of the com.mongodb.BasicDocument, you can't add a second '_id' expression specified as '_id : Document{{$in=[1000090]}}'. Criteria already contains '_id : 1000090'.
  • 报错的原因是因为前面已经用了_id字段查询了又用了_id,语句如下:
Criteria.where("_id").in(id).and("_id").in(userIdArray);
  • 解决方案可以使用andOperator语句
new Criteria().andOperator(Criteria.where("_id").is(id),
                            Criteria.where("_id").in(userIdArray));

posted on 2019-08-31 15:07  愤怒的苹果ext  阅读(5)  评论(0编辑  收藏  举报  来源

导航