Ale*_*ani 5 java spring mongodb spring-data
我正在尝试使用2个以上的可选参数执行查询,但我没有得到任何结果.对于2个参数,我遵循了这个问题的答案spring-data-mongo - 可选的查询参数?.
例如,使用以下查询一切正常:
@Query("{$and: [{$or : [ { $where: '?0 == null' } , { a : ?0 } ]}, {$or : [ { $where: '?1 == null' } , { b : ?1 }]}]}")
Run Code Online (Sandbox Code Playgroud)
但是,如果我再添加一个参数,它就会停止工作:
@Query("{ $and : [{$and: [{$or : [ { $where: '?0 == null' } , { a : ?0 } ]}, {$or : [ { $where: '?1 == null' } , { b : ?1 }]}]},{$or : [ { $where: '?2 == null' } , { c : ?2 }]}]}")
Run Code Online (Sandbox Code Playgroud)
我三重检查语法,似乎没问题,但我得到空结果(即使我确定我应该至少获得几个文件).
任何的想法?
如果您仔细尝试手工格式化查询以使其更易读,您会注意到您使用右括号犯了一些错误.
请尝试此查询:
{ $and :
[{
$and:
[
{$or : [ { $where: '?0 == null' } , { a : ?0 }]},
{$or : [ { $where: '?1 == null' } , { b : ?1 }]},
{$or : [ { $where: '?2 == null' } , { c : ?2 }]}
]
}]
}
Run Code Online (Sandbox Code Playgroud)
旁注:我认为一个$and就足够了,即删除顶级$and操作符.
| 归档时间: |
|
| 查看次数: |
2931 次 |
| 最近记录: |