更新:通过重命名我的模型属性" loc"而不是" location"
我在node.js应用中使用mongoose在mongodb 2.4.x中保存用户位置时遇到问题。我有以下设置:
猫鼬模型:
var UserSchema = new mongoose.Schema({
location: {
type: { type: String },
coordinates: [Number]
}
});
UserSchema.index({ location: '2dsphere' });
的node.js /猫鼬
var userId = "30303030303";
var geoJSON = { "type": "Point", "coordinates": [4.4662489999999995, 51.169115999999995] };
User.findById(userId, function (err, user){
user.location = geoJSON;
user.save();
});
这会触发以下错误:
[MongoError: Can't parse geometry from element: location: "[object Object]"]
name: 'MongoError',
err: 'Can\'t parse geometry from element: location: "[object Object]"',
code: 16700,
n: 0,
connectionId: 449,
ok: 1 }
像彼得说的更新我的模型后,错误现在如下:
err: 'location object expected, location array not in correct format',
有没有人经历过类似的事情或有人知道如何解决这个问题?