【发布时间】:2017-02-16 22:42:53
【问题描述】:
我有一个像这样的 mongoDB 架构:
var PlumberSchema = new Schema({
firstname: {
type: String
},
...
office: {
address:{ type:String },
location: { type:[Number], index: '2d'}
}
...
}
index:'2d' 是我需要为地理空间搜索创建 2D 索引的位置。
为了做到这一点,我已经阅读了文档:https://docs.mongodb.com/manual/tutorial/build-a-2d-index/,并且为了方便我报告了一个示例:
db.<collection>.createIndex( {<location field> : "<index type>"}
如果我的 Schema 是这样的,那对我有帮助:
var PlumberSchema = new Schema({
firstname: {
type: String
},
...
address:{ type:String },
location: { type:[Number], index: '2d'}
...
}
要在这种情况下创建索引,我会写:
db.<collection>.createIndex( {location:"2d"})
但正如你所见,我有一个 嵌套对象。我该怎么办?
【问题讨论】:
标签: mongodb mongoose mongodb-query geospatial mean-stack