【发布时间】:2016-03-05 13:49:12
【问题描述】:
我有一个带有定义架构的 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
我查看了如何在架构中指定默认值,但我看不到在 GeoJSON.Point 数据类型的情况下将值设置为 null。
我也试过
db.collection.update({},{$set:{location:null},{multi:true})
但这似乎也没有帮助。
是不是因为location上的索引?
【问题讨论】:
-
Mongoose 3.6 release notes 建议您使用数组作为类型。
GeoJSON.Point来自哪里? -
我用额外的信息编辑了我的问题
标签: node.js mongodb mongoose geojson