【发布时间】:2019-09-03 21:50:39
【问题描述】:
我正在尝试使用 $geoNear mongoDB 函数查找两点之间的距离并收到以下错误:
MongoError:错误处理查询:ns=Driveoo.vehiclesTree:GEONEAR
field=location maxdist=10000 isNearSphere=0↵Sort: {}↵Proj: {}↵ planner 返回错误:无法找到 $geoNear queryCar Search 的索引 失败
请在下面找到我的代码:
exports.getNearestVehicles = function (req, res, next) {
Vehicle.find({
location: {
$near: {
$maxDistance: 10000,
$geometry: {
type: "Point",
coordinates: [req.query.lat, req.query.long]
}
}
}
}).then( results => {
return responseHandler.resHandler(true,JSON.stringify(results,0,2),"Car Response", res, 200);
})
.catch(error=> {
return responseHandler.resHandler(false,null,error+"Car Search Failed", res, 200);
});
}
谁能解决我哪里做错了?
【问题讨论】:
标签: node.js database mongodb mongoose geolocation