本文介绍了猫鼬-2Dsphere索引-Howto的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Node.js.如何在Mongoose模式上为Polygon配置2dsphere索引?
I am working with Node.js.How can I configure a 2dsphere index for a Polygon on the schema of Mongoose?
我已经尝试过:
location_2dsphere: {
type: { type: String }
, coordinates: []
},
但这不起作用!
推荐答案
这是您的操作方式
location_2dsphere: {
'type': { type: String },
coordinates: []
}
所以关键是使第一个type
成为'type'
So the key thing is to make the first type
to be 'type'
然后记住在您的字段上创建一个2dsphere
索引!
Then remember to create a 2dsphere
index on your field!
在猫鼬中,当您要将一个字段命名为type
或任何其他保留字段时,只需使用括号强制进行字符串转换.
In Mongoose, when you want to name a field as type
or any other reserved field, just force string conversion by using the parentheses.
这篇关于猫鼬-2Dsphere索引-Howto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!