I'm building an e-commerce website where client can browse and filter products.
Well i'm trying to get a response from MongoDB (products list) with a Query, example: http://localhost:3000/Products/Tshirt
, and i should get only products with category= Tshirt
.
My problem is: when i write in the Query tshirt
(with lowercased t), i get no response at all. Which means that the Query string should be exactly same as the one in my database. How to make the Query ignores lowercase and uppercase?
CodePudding user response:
you can use regex. let say your collection is products and you are searching from the field called name.you can do as below.
db.products.find( { name: /^Tshirt$/i } );
in here Tshirt is the word that you are getting from the frontend.This word can be anything such as tshirt,TSHIRT.