【发布时间】:2021-02-09 19:08:30
【问题描述】:
我必须根据与当前位置的距离来过滤帖子。附上下面的代码以供参考,但它不起作用(虽然计算距离工作正常),只有在距离条件似乎不起作用的情况下。另外,当我在 top where 条件下尝试距离过滤器时,它会抛出 post.distance column not found 错误
const posts = await Post.findAll({
where: {
mobile: {
[Op.ne]: mobile,
},
},
attributes:
include: [
[
db.Sequelize.fn(
"ST_Distance",
db.Sequelize.col("location"),
db.Sequelize.fn(
"ST_MakePoint",
parsedLocation.lat,
parsedLocation.lng
)
),
"distance",
],
],
where: {
distance: {
[Op.between]: [
0,100
],
},
},
},
include: {
model: UserProfile,
attributes: ["username"],
},
});
【问题讨论】:
-
你使用什么数据库?
-
我使用 Postgres 数据库
标签: javascript node.js sequelize.js