如何使用jongo runcommand为以下示例执行regex:
Command command = jongo.runCommand("{" +
"find : 'sales', filter : {$and : [{date : {$gte : #}},"
+ "{date : {$lte : #}}, { name: { $regex: /^TEST/ } } ]} "
+ "}", d1,d2);
List<MyDate> t = command.throwOnError().field("cursor").as(MyDate.class);
它给我这个例外:
{find : 'sales', filter : {$and : [{date : {$gte : #}},{date : {$lte : #}}, { name: { $regex: /^TEST/ } } ]} }
at org.jongo.query.BsonQueryFactory.createQuery(BsonQueryFactory.java:233)
at org.jongo.Command.<init>(Command.java:43)
at org.jongo.Jongo.runCommand(Jongo.java:69)
at com.mtrojahn.boot.JongoTest.start(JongoTest.java:152)
at com.mtrojahn.boot.JongoTest.main(JongoTest.java:50)
Caused by: com.mongodb.util.JSONParseException:
Regards
Kris
答案 0 :(得分:0)
发现答案使用$ regex
的$ options重新构建了查询 像这样: {find : 'sales', filter : {$and : [{date : {$gte : #}},{date : {$lte : #}}, { 'name' : { '$regex' : "^Test" , "$options" : "i"} ]} }