0

How to use jongo runcommand to execute regex for the below example :

       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);

Its throwing me this exception :

   {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
chiku
  • 485
  • 2
  • 8
  • 23

1 Answers1

0

Found the answer reframed the query with $options with $regex

like this :

   {find : 'sales', filter : {$and : [{date : {$gte : #}},{date : {$lte : #}}, { 'name' : { '$regex' : "^Test" , "$options" : "i"} ]}  }
chiku
  • 485
  • 2
  • 8
  • 23