鍍金池/ 問(wèn)答/數(shù)據(jù)庫(kù)/ sequelize findAll時(shí)提示 Invalid value

sequelize findAll時(shí)提示 Invalid value

如果不使用$like查詢(xún)是沒(méi)問(wèn)題的,但是業(yè)務(wù)需要模糊搜索功能。
一旦使用$likeInvalid value

連接數(shù)據(jù)庫(kù)

var sequelize = new Sequelize('data', 'root', 'Root123', {
  host: 'localhost',
  dialect: 'mysql',
  dialectOptions: {
    charset: 'utf8mb4'
  },
  pool: {
    max: 5, // 連接池中最大連接數(shù)量
    min: 0, // 連接池中最小連接數(shù)量
    idle: 10000 // 如果一個(gè)線程 10 秒鐘內(nèi)沒(méi)有被使用過(guò)的話,那么就釋放線程
  },
  operatorsAliases: false,
});

定義模型

var patient = sequelize.define('patient', {
  user: Sequelize.TEXT,
  sex: Sequelize.STRING,
  age: Sequelize.INTEGER,
  num: Sequelize.INTEGER,
  bed: Sequelize.INTEGER,
  department: Sequelize.STRING,
}, {
  // 不加會(huì)導(dǎo)致出現(xiàn)復(fù)數(shù)users未找到的錯(cuò)誤
  freezeTableName: true,
  timestamps: false
});
patient.removeAttribute('id')
patient.removeAttribute('createdAt')
patient.removeAttribute('updatedAt')

查詢(xún)

router.post("/searchPatient", function (req, res, next) {
  console.log(req.body.val)
  patient.findAll({
    where: {
      num: {
        $gte: 4
      }
      /* $or: [{
          user: req.body.val
        },
        {
          num: req.body.val
        }
      ] */
    }
  }).then(function (doc) {
    if (doc.length != 0) {
      console.log(doc)
    } else {
        // ...
    }
  }).catch(function (err) {
    console.log('錯(cuò)誤' + err)
  })
});

提示錯(cuò)誤Error: Invalid value { '$gte': 4 }

回答
編輯回答
硬扛

中文文檔看漏了,現(xiàn)在用const Op = Sequelize.Op;[Op.or]: [{}]去篩選。。

2017年1月21日 01:54