[英]How to make Query ignores lowercase and uppercase?
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
.好吧,我正在尝试使用查询从 MongoDB(产品列表)获得响应,例如: http://localhost:3000/Products/Tshirt
,我应该只获得 category= Tshirt
的产品。
My problem is : when i write in the Query tshirt
(with lowercased t), i get no response at all.我的问题是:当我在查询 T tshirt
(小写的 t)中写入时,我根本没有得到任何回应。 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?如何使查询忽略小写和大写?
you can use regex.你可以使用正则表达式。 let say your collection is products and you are searching from the field called name.you can do as below.假设您的收藏是产品,并且您正在从名为 name.you 的字段中搜索。您可以执行以下操作。
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.在这里,Tshirt 是你从前端得到的词。这个词可以是任何东西,例如 tshirt、TSHIRT。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.