我有一个具有已定义架构的 mongodb 集合,并且我更新了此架构以包括纬度/经度坐标。
旧版本:
var schema = mongoose.Schema({
id: String,
name: String,
address: String,
city: String,
zip: String,
country: String,
phoneNumber: String,
mobile: String,
website: String,
email: String,
});
新版本
var schema = mongoose.Schema({
id: String,
name: String,
address: String,
city: String,
zip: String,
country: String,
phoneNumber: String,
mobile: String,
website: String,
email: String,
location: GeoJSON.Point
});
schema.index({ location: '2dsphere' });
GEOJSON.Point
来自mongoose-geojson-schema
看起来像这样:
GeoJSON.Point = {
'type' : { type: String, default: "Point" },
coordinates: [
{type: "Number"}
]
}
在我添加之前该集合已经包含数据location
财产。
显然现在发生的事情是由于某种原因 mongodb 使用{ coordinates: [], type: "Point" }
作为现有文档的默认值,我收到如下错误:
MongoError: Can't extract geo keys: { _id: ObjectId('5637ea3ca5b2613f37d826f6'), ...
Point must only contain numeric elements
我已经研究了如何在架构中指定默认值,但我看不到如何将该值设置为null
对于 GeoJSON.Point 数据类型。
我也尝试过
db.collection.update({},{$set:{location:null},{multi:true})
但这似乎也没有帮助。
是不是因为上面的索引location
?