node.js - 使用距离过滤 mongodb 文档
问题描述
我很难使用用户的坐标(最大距离)过滤文档。
我的请求如下所示:
app.post('/item', checkAuth, function(request, response) {
var location = request.body.location;
var distance = request.body.distance;
Item.find( { "location": {
$near: { $geometry: { type: "Point",
coordinates: [location.longitude, location.latitude] },
$maxDistance: distance
}
} }, function(err, items) {
if (err) {
response.status(500).send({error: err});
} else {
response.send({items : items,
message: 'Fetching items successful'
});
}
});
});
解决方案
推荐阅读
- c# - SQL 如何替换一个值
- python - 使用 python 和请求,如何进行正确的 POST 调用以及在哪里找到标头?
- android - FirebaseAppDistribution:appDistributionUpload gradle 命令中缺少应用程序 ID
- mysql - 跨列和行计算值的实例
- javascript - 使用 redux 钩子时使用 redux 操作的最佳选择是什么?
- sql - Impala 2.11:AnalysisException:选择列表中不支持子查询
- swift - 在 SwiftUI 中获取当前的经纬度
- c++ - 是否可以禁止一个类被动态转换为?
- git - Git - 将发布分支合并到主分支
- tensorflow - 任何想法如何解决激活函数的问题?