MongoDB错误“无法从对象提取地理密钥,格式不正确?

我有这个代码:

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? 

我看到一些类似于我的问题,但他们的解决scheme是添加我已经添加的ensureIndex。

我们可以看到你的坐标是string: ["32.081473", "32.08473"]而他们应该是数字。 在模式定义中,坐标必须定义为一个Numbers数组:

 var VehicleSchema = new Schema({ loc: { type: { type: String }, coordinates: [Number] }, });