let { name } = req.query;
// console.log(name)
// const escapedName = new RegExp.escape(name);
let query = { name: { $regex: name ,$options:‘i’ } };
console.log(name)
let tour = await tourmodel.find({query}).sort({price:1})
res.send(tour)
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 .
steevej
(Steeve Juneau)
July 4, 2024, 3:50pm
7
In
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 : ...
2 Likes
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 !!
steevej
(Steeve Juneau)
July 4, 2024, 10:28pm
9
Because with the query equals to
steevej:
query : { name : … }
you were query a field named query to have the value name:… rather than a field named name .
steevej
(Steeve Juneau)
July 6, 2024, 1:35pm
10
yash_mondal:
The issue is solved
Please mark one of the post as the solution.
Ad Thanks vance