Node.js MongoDB错误“;can';“是否从对象中提取地理关键点,几何体格式不正确?”;
我有以下代码:Node.js MongoDB错误“;can';“是否从对象中提取地理关键点,几何体格式不正确?”;,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我有以下代码: db.Vehicles.ensureIndex({"location":"2dsphere"}); db.vehicles.find({ "location": { $near: { $geometry: { type: "Point", coordinates: [32.081473, 32.081473] }, $maxDistance: 5000 }
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。我们可以看到您的坐标是字符串:
[“32.081473”,“32.08473”]
而它们应该是数字。在模式定义中,坐标必须定义为数字数组:
var VehicleSchema = new Schema({
loc: {
type: {
type: String
},
coordinates: [Number]
},
});
你能检查一下你的坐标吗?它是字符串,应该是数字格式。如何插入
位置数据?@chridam为什么?我试过,但仍然是同样的错误-维斯瓦斯-我也试过同样的错误-戴夫-我在问题里写的。我用的是机器人