What is Query conversion for Compass query in spring Mongo template

16 Views Asked by At
My requirement is to get employees where id starts with 11 only from mongo DB.

Working query in Mongo compass for me:
{ $where: "/^11.*/.test(this.empId)" }    //succcess

but when I try to use it in Spring template using the below, it does not return result.
1st attempt:

query = new Query()
    .addCriteria(Criteria.where("/^11.*/.test(this.empId)"))
    .with(Sort.by(Sort.Direction.DESC, "empId"));


2nd Attempt
@Query(value =  "/^77.*/.test(this.empId) ",sort = "empId': -1")

Please advice on how to generate the above Success query through Spring.

0

There are 0 best solutions below