无法提取地理位置密钥,未知的GeoJSON类型:{坐标:[13.42493130000003,52.50074619999999] [英] Can't extract geo keys, unknown GeoJSON type: { coordinates: [ 13.42493130000003, 52.50074619999999 ]
问题描述
我有此表格可获取用户信息,该用户已正确保存了位置.
I have this form where I get the info of a user, the user has been saved with a location correctly.
但是当我尝试对其进行更新时,它会给我这个错误:
But when i try to update it, it gives me this error back:
> Can't extract geo keys: { _id: ObjectId('5c4eb6c94f59c09ee7490ee0'),
> salt:
> "d0ca72b02426c59da828fd65fff93e94ed7c4529f46db883c1f1cfa406be92ce",
> hash:
> "442a59e8ef32f4d309a1d2a71575c11a6d382e514d75f010e1228e8156ffa8ce71b7451c34b09319780744cc3e50e74e2e25d9ff75e8c7519087bddfa32b906801ed287ded16897c90ac15...",
> email: "jorgeantonio82@gmail.com", name: "Jorge", location: {
> coordinates: [ 13.42493130000003, 52.50074619999999 ], address:
> "Naunynstraße 81, Berlin, Germany" }, created: new
> Date(1548662473107), genres: null, props: [], __v: 0, musicLink:
> "soundcloud" } unknown GeoJSON type: { coordinates: [
> 13.42493130000003, 52.50074619999999 ], address: "Naunynstraße 81, Berlin, Germany" }
我的用户拥有我认为需要的所有东西:
My user has all the stuff i think it needs:
const userSchema = new Schema({
email: {
type: String,
unique: true,
lowercase: true,
trim: true,
validate: [validator.isEmail, 'Invalid Email Address'],
required: 'Please Supply an email address'
},
name: {
type: String,
required: 'Please supply a name',
trim: true
},
resetPasswordToken: String,
resetPasswordExpires: Date,
props: [
{ type: mongoose.Schema.ObjectId, ref: 'User' }
],
// New stuff
slug: String,
genres: [String],
musicLink: String,
created: {
type: Date,
default: Date.now
},
location: {
type: {
type: String,
default: 'Point'
},
coordinates: [{
type: Number,
required: 'You must supply coordinates!'
}],
address: {
type: String,
required: 'You must supply an address!'
}
},
photo: String,
});
userSchema.index({ location: '2dsphere' })
当我保存它时,有一个控制器仅推送某些内容来更新用户:
And when i save it there is a controller that pushes only certain stuff to update the user:
exports.updateAccount = async (req, res) => {
const updates = {
name: req.body.name,
email: req.body.email,
musicLink: req.body.musicLink,
genres: req.body.tags,
location: {
address: req.body.location.address,
coordinates: [
req.body.location.coordinates[0],
req.body.location.coordinates[1],
]
}
};
console.log('coordinates: ', updates.location.coordinates)
const user = await User.findOneAndUpdate(
{ _id: req.user._id },
{ $set: updates },
{ new: true, runValidators: true, context: 'query' }
);
req.flash('success', 'Updated the profile!');
res.redirect('back');
};
任何想法可能是什么问题?
Any idea what might be the issue?
谢谢.
推荐答案
在
As specified in Mongoose docs (and in the underlying standard for the GeoJSON format), a geometry object must contain a "geometry type" with a value of one of
七个区分大小写的字符串:"Point","MultiPoint","LineString", "MultiLineString","Polygon","MultiPolygon"和"GeometryCollection"
seven case-sensitive strings: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", and "GeometryCollection"
错误消息
unknown GeoJSON type: { coordinates: [13.42493130000003, 52.50074619999999 ]
引用对象中缺少的type属性.包括type
以避免错误:
refers to the missing type property in the object. Include type
to avoid the error:
{type: "Point", coordinates: [13.42493130000003, 52.50074619999999 ]}
这篇关于无法提取地理位置密钥,未知的GeoJSON类型:{坐标:[13.42493130000003,52.50074619999999]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!