2

我正在使用 Mongoose 和Mongoose-geojson-schema但是我无法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.
4

1 回答 1

0

我认为你不能那样使用 Mongoose-geojson-schema,它会弄乱“类型”属性 - 试试这个:

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

 mySchema.path('area').index({ type: '2dsphere'});
于 2015-10-20T19:42:51.983 回答