我正试图找回100万米范围内的所有培训师,但旧的猫鼬geoNear方法已过时。.新方法是使用聚合管道。 请帮忙 :( 当然,有一种更简单的方法可以做到这一点.....
这是我的获取请求
```router.get("/trainers", function(req, res, next) {
Trainer.aggregate([
{
$geoNear: {
near: {
$geometry: {
type: "Point",
coordinates: [parseFloat(req.query.lng),
parseFloat(req.query.lat)]
},
distanceField: dist.calculated,
$maxDistance: 100000,
spherical: true
}
}
}
])
.then(trainers => {
res.send(trainers);
})
.catch(next);
});```
这是我的架构
```const GeoSchema = new Schema({
type: {
type: String,
default: "Point"
},
coordinates: {
type: [Number],
index: "2dsphere"
}
});
const TrainerSchema = new Schema({
name: {
type: String,
required: [true, "Name field is required"]
},
skill: {
type: String
},
available: {
type: Boolean,
default: false
},
geometry: GeoSchema
});```
期望在100万米范围内找回所有教练员