我有以下架构:
module.exports = function (mongoose) {
var Location = mongoose.Schema({
street: String,
number: String,
zip: String,
floor: String,
rental: String,
size: Number,
loc: {
type: {type: String},
coordinates: []
},
updated: {type: Date, default: Date.now}
});
return mongoose.model('Location', Location);
};
我正在尝试通过以下方式查询数据:
mongoose.models.Location.find({
loc: {
$near: [55.69841959999999,12.5443359],
$maxDistance: 2000
}
}, function (err, doc) {
res.json(doc);
});
但是我收到一条错误消息:
> error processing query: ns=RentalDB.locationsTree: GEONEAR field=loc maxdist=2000 isNearSphere=0
Sort: {}
Proj: {}
planner returned error: unable to find index for $geoNear query
谁能告诉我我做错了什么?
最佳答案
存储时您的地理数据应采用正确的格式。
坐标是数字而不是字符串
引用:https://docs.mongodb.com/manual/geospatial-queries/#legacy-coordinate-pairs
关于javascript - Mongoose 在坐标上抛出错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46075204/