我正在寻找容量大于或等于输入容量的房间。我正在使用$gte
运算符,它总是返回一个空数组。
我正在使用sequelize和MySQL,当我尝试时,
let allRooms = await Room.findAll({
where: {
capacity: 9
}
});
I get an array containing the data I'm trying to get.
[ Room {
dataValues:
{ id: 2,
name: 'meeting room 1',
amenities: <Buffer 00 00 00>,
capacity: 9,
createdAt: 2019-08-26T18:21:07.000Z,
updatedAt: 2019-08-26T18:21:07.000Z,
locationId: 1 }
}
]
但是当我尝试
let allRooms = await Room.findAll({
where: {
capacity: { $gte: 5 }
}
});
it returns // []
在我的终端上,我得到了
Executing (default): SELECT `id`, `name`, `amenities`, `capacity`,
`createdAt`, `updatedAt`, `locationId` FROM `Rooms` AS `Room`
WHERE `Room`.`capacity` = '[object Object]';
答案 0 :(得分:0)
您尝试过
const Op = Sequelize.Op
let allRooms = await Room.findAll({
where: {
capacity: { [Op.gte]: 5 }
}
});
编辑:
别名必须在使用前声明
const Op = Sequelize.Op
const operatorsAliases = {
$gte: Op.gte
}
let allRooms = await Room.findAll({
where: {
capacity: { $gte: 5 }
}
});