Sails.js升级到v1反向区分大小写的查询 [英] Sails.js upgrade to v1 reverse case sensitive queries

查看:86
本文介绍了Sails.js升级到v1反向区分大小写的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到Sails v1后,控制器中的所有请求都区分大小写.

After upgrading to sails v1 all the requests in the controllers became case sensitive.

尽管这是预期的,但请在此处评论: https: //sailsjs.com/documentation/concepts/models-and-orm/models#?case-sensitive ,我希望具有不区分大小写的行为.

Although this is expected, commented here: https://sailsjs.com/documentation/concepts/models-and-orm/models#?case-sensitivity, I would like to have case insensitive behavior.

在我的查询中,这是一个问题,我无法找到使它再次变为NON区分大小写的方法. 我在生产中使用MongoDB.

In my queries this is a problem and I am not able to figure out a way to make it NON case sensitive again. I am using MongoDB in production.

任何帮助或建议都将不胜感激.

Any kind of help or suggestion would be much appreciated.

推荐答案

对于MongoDB,我们需要执行本机mongo查询以使其不区分大小写:

For MongoDB we need to do a native mongo query to get case-insensitive:

const collection = Pet.getDatastore().manager.collection(Pet.tableName);
const res = await collection.find({ name: { $regex: /blue/, $options: 'i' } });
const dataWithObjectIds = await res.toArray();
const dataWithIds = JSON.parse(JSON.stringify(rawDataArr).replace(/"_id"/g, '"id"'));

有关本地mongo查询的更多信息,请参见此处- https://stackoverflow.com/a/54830620/1828637

See here for more on native mongo query - https://stackoverflow.com/a/54830620/1828637

这篇关于Sails.js升级到v1反向区分大小写的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆