【发布时间】:2016-07-13 09:41:49
【问题描述】:
我有一个结构如下的数据库:
{
"_id" : ObjectId("5785663bda7b71a0c5601c89"),
"visible" : true,
"created" : {
"changeset" : "29670315",
"user" : "samit_53",
"version" : "1",
"uid" : "2297171",
"timestamp" : "2015-03-23T03:59:14Z"
},
"type" : "node",
"id" : "3413812873",
"pos" : [
22.1173487,
88.0034742
]
}
现在我在 pos 上有 '2d' 索引
>>db.kol_sample.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "project_sample.kol_sample",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"pos" : "2d"
},
"ns" : "project_sample.kol_sample",
"name" : "pos_2d"
}
]
现在,当我只使用 $near 进行查询时,我会得到 100 个结果
db.kol_sample.findOne({"pos":{$near:[22,88]}})
{
"_id" : ObjectId("5785663bda7b71a0c5601c89"),
"visible" : true,
"created" : {
"changeset" : "29670315",
"user" : "samit_53",
"version" : "1",
"uid" : "2297171",
"timestamp" : "2015-03-23T03:59:14Z"
},
"type" : "node",
"id" : "3413812873",
"pos" : [
22.1173487,
88.0034742
]
}
但是在我添加 $maxDistance 参数之后,无论我通过什么距离,它总是返回 null
db.kol_sample.findOne({"pos":{$near:[22.1173487,88.0034742]},$maxDistance:100})
null
MongoDB shell 版本:2.4.9 32bit
【问题讨论】:
标签: mongodb indexing geolocation geospatial database