首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mongoose -如何在自定义类型上添加2dsphere索引?

Mongoose -如何在自定义类型上添加2dsphere索引?
EN

Stack Overflow用户
提问于 2015-10-20 23:10:45
回答 1查看 1K关注 0票数 2

我正在使用Mongoose和Mongoose-geojson-schema,但是我不能在我的字段中添加2dsphere索引:

代码语言:javascript
复制
new Schema({
  district: {
    type: String,
    trim: true,
    unique: true,
    required: true
  },
  area: {
    type: GeoJSON.FeatureCollection,
    index: '2dsphere'
  }
});

得到这样的错误:

代码语言:javascript
复制
/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.
EN

回答 1

Stack Overflow用户

发布于 2015-10-21 03:42:52

我认为你不能这样使用Mongoose-geojson-schema,它会弄乱'type‘属性--试试这个:

代码语言:javascript
复制
var mySchema = new Schema({
    district: {
        type: String,
        trim: true,
        unique: true,
        required: true
    },
    area: GeoJSON.FeatureCollection
 });

 mySchema.path('area').index({ type: '2dsphere'});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33240313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档