【问题标题】:Find matching objects on Sequelize backend query在 Sequelize 后端查询中查找匹配对象
【发布时间】:2020-03-25 21:32:04
【问题描述】:

我们正在使用 Sequelize 和 Express 开发 MariaDB 后端,我们需要找到每个包含不完整字符串的匹配对象,我的意思是,如果有人搜索 JO 并且数据库条目是 JO2019 这应该被列出,以及包含JO 的所有内容,但事实并非如此。我们已经尝试过 [OP.like],但它没有返回数据。

提前致谢,我们接受任何帮助。

accidents_basics.trobar = async (req, res) => {
 const nep_cercat = req.query.nep;
  const data = await Accident.findAll({
    where: {nep: nep_cercat},
    
  })
  const data1 = await AccidentDatos.findAll({
	where: {nep:{ [Op.Like]: nep_cercat},}

  })  
  .then( function(data){
    return data;
  })
  .catch(error => {
    return error;
  })
  res.status(200).json({
    success:true,
    message:"Se han encontrado los datos!",
    data:data, data1, nep_cercat
  })

}

【问题讨论】:

    标签: sql express mariadb sequelize.js


    【解决方案1】:

    我可以建议您使用正则表达式行为而不是应用程序:

      const data1 = await AccidentDatos.findAll({
        where: {nep:{ [Op.regexp]: nep_cercat},}
      }) 
    

    如果你不在'like'研究中包含'%',你可能无法获得goog结果......

    【讨论】:

      猜你喜欢
      • 2013-04-07
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 2013-07-27
      • 2022-12-11
      • 2020-06-29
      • 2017-07-20
      • 2023-04-06
      相关资源
      最近更新 更多