Sequelize:查找与查询匹配的所有内容(不区分大小写)

Sequelize: Find All That Match the query (Case Insensitive)

如果我有一个 context.data.filename ='DOC.doc' 并且数据库记录包含例如 DOC.doc 和 DOC-1.doc 的记录,那么它应该 return 两者带有 employeeId 的数据,但现在只有 returns DOC.doc 匹配这是错误的,它也应该 return DOC-1 因为它匹配模式。

伙计们有什么想法吗?将不胜感激,谢谢。

#代码

  const file = await context.service.Model.findAll({
    where: {
      filename: {
        [Op.like]: `%${context.data.filename}%`,
      },
      employeeId: record.id,
    },
    paranoid: false,
  });

这不是sequelize的问题。如果您正在搜索 DOC.doc 并想查找 DOC-1.doc,则需要将 % 符号放在点之前。 % 表示“任意数量的任意字符”。所以你的搜索查询应该看起来像 DOC%.doc.

例如:

const filename = '%' + context.data.filename.replace('.', '%.')  + '%';
const file = await context.service.Model.findAll({
    where: {
      filename: {
        [Op.like]: filename,
      },
      employeeId: record.id,
    },
    paranoid: false,
});