gpt4 book ai didi

node.js - $geoWithin 查询形式 mongodb 到 mongoose 语句

转载 作者:太空宇宙 更新时间:2023-11-04 01:05:09 25 4
gpt4 key购买 nike

从 mongodb 获取此查询:

 db.location.find(
{loc: { $geoWithin: { $centerSphere: [ [ 9, 9],
radius ] } }, action:1 })
.limit(10)
.skip(1, function(err, result) {
console.dir(result);
});

如何使用 geoWithin 将其转换为 mongoose 语句?

最佳答案

嗯,像这样的事情:

 LocationModel.where('loc').within({ center: [ your_lat, your_lng], radius: your_radius, unique: true, spherical: true }).where('action').equals(your_action).skip(your_skip).limit(10).exec(
function(err, result) {
console.dir(result);
});

之前当然需要创建LocationModel和LocationSchema,我希望它能有所帮助。

关于node.js - $geoWithin 查询形式 mongodb 到 mongoose 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23720963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com