我正在尝试通过 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)