2015-10-20 50 views
1

我使用的猫鼬与Mongoose-geojson-schema但是我不能在我的字段添加2dsphere指数:Mongoose - 如何在自定义类型上添加2dsphere索引?

new Schema({ 
    district: { 
    type: String, 
    trim: true, 
    unique: true, 
    required: true 
    }, 
    area: { 
    type: GeoJSON.FeatureCollection, 
    index: '2dsphere' 
    } 
}); 

获得这样的错误:

/Users/dmitri/api/node_modules/mongoose/lib/schema.js:479 
    throw new TypeError('Undefined type `' + name + '` at `' + path + 
    ^
TypeError: Undefined type `2dsphere` at `area.index` 
    Did you try nesting Schemas? You can only nest using refs or arrays. 

回答

0

我认为你不能用猫鼬,GeoJSON的图式那样,它弄乱了“类型”属性 - 试试这个:

var mySchema = new Schema({ 
    district: { 
     type: String, 
     trim: true, 
     unique: true, 
     required: true 
    }, 
    area: GeoJSON.FeatureCollection 
}); 

mySchema.path('area').index({ type: '2dsphere'}); 
相关问题