以下示例说明如何使用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发布于 2018-01-08 22:59:33
找到了答案使用$options和$regex重新构造了查询
如下所示:
{find : 'sales', filter : {$and : [{date : {$gte : #}},{date : {$lte : #}}, { 'name' : { '$regex' : "^Test" , "$options" : "i"} ]} }https://stackoverflow.com/questions/48144975
复制相似问题