简体   繁体   中英

How to use the .find() method in Sails.js v1 to search case-insensitive

Long story short, the find method search in a case-sensitive way, I want it to search in non case-sensitive. Make Contains Modifier Case Insensitive In Mongo.

return res.send(await Template.find({
  where: { 'title' : { startsWith : 'f' }
}));

In my case, I solved it this way:

ALTER TABLE 'some_table' convert TO CHARACTER SET utf8 COLLATE utf8_unicode_ci

Sails documentation say "In order to fix this you can set the tables in your MySQL database to a case sensitive collation such as utf8_bin." I use "utf8_unicode_ci" becouse this is case-insensitive collation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM