I am unable to make the regex insensitive

let { name } = req.query;

// console.log(name)
// const escapedName = new RegExp.escape(name);
let query = { name: { $regex: name ,$options:‘i’ } };


let tour = await tourmodel.find({query}).sort({price:1})


I am using this code but nothing is happening ??

Hello @yash_mondal,

If you are not getting any error then don’t you think you need to debug your code yourself and provide more details?

Please provide the details:

  • provide the sample document.
  • what is the value of name?
  • as per the existing document, input search what is your expected result?
1 Like

I debugged it no issues but actually i think some syntax issues or I don’t now because I am passing
the values and in console.log() … I am getting the values but regex is not working like If i pass the value as ABC after regex where i should be getting as abc but i am still getting ABC . So , can you guide sir

Hello @yash_mondal,

You can check the same example of ABC here in the playground, it should work, and I don’t see any issue in your code.

Something is wrong that is not present in your provided details.

sir if I provide you the full code will you be able to verify ?? becoz i need to correct it . I don’t know why it’s not working sir .


Try removing the curly braces around {query}.

The way it is written, you probably end up sending

query : { name : … }

As the query rather than

name : ...


The issue is solved . Thanks steevej , I will also request you why i was not getting my desired result can you say . why it was not showing !!

Because with the query equals to

you were query a field named query to have the value name:… rather than a field named name.

Please mark one of the post as the solution.

Ad Thanks vance