我有这段代码:
db.Vehicles.ensureIndex({"location":"2dsphere"});
db.vehicles.find({
"location": {
$near: {
$geometry: {
type: "Point",
coordinates: [32.081473, 32.081473]
},
$maxDistance: 5000
}
}
})
我的位置是:
location":{"type":"point", "coordinates": ["32.081473", "32.08473"]}
我收到错误:
err: can't extract gel keys from object, malformed geometry?
我看到一些看起来像我的问题,但他们的解决方案是添加了我已添加的ensureIndex。
答案 0 :(得分:0)
我们可以看到您的坐标是字符串:["32.081473", "32.08473"]
而他们应该是数字。在模式定义中,坐标必须定义为Numbers数组:
var VehicleSchema = new Schema({
loc: {
type: {
type: String
},
coordinates: [Number]
},
});