Node.js 模式中的mongoose geojson;Can';t提取地理关键帧“;错误

Node.js 模式中的mongoose geojson;Can';t提取地理关键帧“;错误,node.js,mongodb,mongoose,geojson,Node.js,Mongodb,Mongoose,Geojson,我有一个定义了模式的mongodb集合,我更新了这个模式以包含lat/lon坐标 旧版本: var schema = mongoose.Schema({ id: String, name: String, address: String, city: String, zip: String, country: String, phoneNumber: String, mobile: String, website: Stri

我有一个定义了模式的mongodb集合,我更新了这个模式以包含lat/lon坐标

旧版本:

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模式
,如下所示:

GeoJSON.Point = {
  'type'     : { type: String, default: "Point" },
  coordinates: [
    {type: "Number"}
  ]
}
在我添加
location
属性之前,集合已包含数据

显然,由于某种原因,mongodb使用
{coordinates:[],键入:“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})
但这似乎也没什么帮助


是因为
位置上的索引吗?

我认为您需要升级
GeoJSON。点
到具有适当架构的a:

GeoJSON.Point = new mongoose.Schema({
  'type'     : { type: String, default: "Point" },
  coordinates: [ { type: "Number" } ]
});

与默认启用的选项相结合,这将使Mongoose仅保存
location
属性(如果实际设置了该属性)。

我建议您不要将
GeoJSON.Point
用作模式类型。只要使用混合对象类型,一切都会正常工作

location: Schema.Types.Mixed

Mongoose3.6建议使用数字数组作为类型。
GeoJSON.Point
从哪里来?我用额外的信息编辑了我的问题