小编Dik*_*hra的帖子

未能添加第二个“$or”表达式

我正在尝试通过 Java API 查询带有两个“或”子句的 mongodb 集合。通过任何 mongo 客户端运行时,以下查询工作正常:

{
  $and : [{
    $or : [ { “field1” : “value1”}, {“field1” : “value2”}]
 },{
    $or : [ { “field2” : “value3”} , { “field2” : “value4”}]
 }]
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用 Java API 运行它时,出现以下错误:

org.springframework.data.mongodb.InvalidMongoDbApiUsageException: Due to limitations of the com.mongodb.BasicDBObject, you can't add a second '$or' expression specified as '$or : [ { “field1” : “value1”}, {“field1” : “value2”}]'. Criteria already contains '$or : [ { “field2” : “value3”} , { “field2” …
Run Code Online (Sandbox Code Playgroud)

java spring mongodb

5
推荐指数
2
解决办法
5649
查看次数

标签 统计

java ×1

mongodb ×1

spring ×1