【发布时间】:2014-07-18 08:43:01
【问题描述】:
我有一个猫鼬模式,其子文档包含一个位置字段(带有 2dSpehre 索引)。像这样:
var playerSchema = new mongoose.Schema({
name: { type: String, required: true },
addresses: [
{
address: {
street: String,
city: String,
zip: String,
country: String
},
loc: { type: [Number], index: '2dSphere' }
}
],
});
当我尝试通过地理空间运算符查询地址时,我收到此错误:planner returned error: unable to find index for $geoNear query。查询如下所示:
var query = {
'addresses.loc': {
$nearSphere: {
$geometry: { type: 'Point', coordinates: [16.3738189, 48.2081743] }
}
}
};
Player.find(query).exec();
我还通过 mongo 检查了索引确实存在:
> db.player.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "project.player"
},
{
"v" : 1,
"key" : {
"addresses.loc" : "2dsphere"
},
"name" : "addresses.loc_2dsphere",
"ns" : "project.player",
"2dsphereIndexVersion" : 2
}
]
我做错了什么?提前致谢。
【问题讨论】: