我正在使用Node.js.How,我可以在Mongoose的模式上为多边形配置一个2dsphere索引吗?
我已经尝试过了:
location_2dsphere: {
type: { type: String }
, coordinates: []
},但是它不起作用!
发布于 2013-07-06 06:05:36
这就是你怎么做的
location_2dsphere: {
'type': { type: String },
coordinates: []
}所以关键是让第一个type成为'type'
然后记得在你的字段上创建一个2dsphere索引!
在Mongoose中,当您想要将字段命名为type或任何其他保留字段时,只需使用括号强制字符串转换即可。
发布于 2021-06-01 17:56:34
在顶层:
db.collections.<yourcollection>.createIndex({ <location_field> : "2dsphere" })where db = mongoose.connection
请注意,在集合本身之前有一个“collection”属性。如果它不工作,请检查console.log中的db对象:
console.log(db)https://stackoverflow.com/questions/17485036
复制相似问题