简体   繁体   English

如何使查询忽略小写和大写?

[英]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.

相关问题 如何使我的前缀适用于小写和大写? - how to make my prefix works on lowercase and uppercase? 如何在字符串upperCase或lowerCase中制作特定单词? - How to make specific word in string upperCase or lowerCase? 如何使jQuery活动状态忽略大写或小写进行url检测 - How to make jQuery active state ignore uppercase or lowercase for url detection 如何将一半的srting用大写,另一半用小写? - how to make half of the srting in uppercase and the other half in lowercase? 如何制作从大写变为小写的单个按钮 - how to make a single button that changes from uppercase to lowercase 如何使我的搜索表单使用大写和小写 - How can I make my search form work with uppercase and lowercase 如何使用 javascript 制作密码生成器,我可以在其中切换长度、特殊字符、数字、大写和小写 - How to make a password generator with javascript where i can toggle length, special characters, numbers, uppercase and lowercase 如何在Javascript中获取大写小写的AsCII代码 - How to obtain AsCII Code of a lowercase of an Uppercase in Javascript 如何使用正则表达式javascript将大写更改为小写 - how to change uppercase to lowercase with regex javascript 如何在ckeditor中将大写节点转换为小写? - how convert uppercase node into lowercase in ckeditor?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM