gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 02:21:20 25 4
gpt4 key购买 nike

我正在将 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.

最佳答案

我认为你不能那样使用 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'});

关于node.js - Mongoose - 如何在自定义类型上添加 2dsphere 索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33240313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com