【发布时间】:2015-04-07 19:35:13
【问题描述】:
我使用 mongolab 作为我的数据库主机。 我创建了位置架构并确保索引“2dsphere” 文档示例:
{
"_id": {
"$oid": "54d6347ce4b04aad9bbdc8ac"
},
"name": "Vacation",
"address": {
"city": "Ashkelon",
"street": "Afridat"
},
"location": {
"type": "Point",
"coordinates": [
34.552955,
31.671384
]
}
}
当使用 Mongoose 查询集合时,一切正常,但我无法检索位置字段。 使用 mongo shell 时,我得到了完整的文档(带有位置)。
// the query Im using:
Mongoose: locations.find({ _id: ObjectId("54d63538e4b04aad9bbdc8b4") }) { fields: undefined }
此查询仅返回以下字段:名称、地址和 _id。
更新:
架构:
var locationSchema = mongoose.Schema({
name: String,
address: {city: String, street: String},
location: {
type: [Number], // [<longitude>, <latitude>]
index: '2dsphere' // create the geospatial index
}
});
【问题讨论】:
-
你能发布你的架构定义吗?
-
我更新了我的问题