$near 查询 returns 添加 $maxDistance 后有 0 个结果
$near query returns 0 results after adding $maxDistance
我有一个结构如下的数据库:
{
"_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 参数后,无论我经过多远,它总是 returns null
db.kol_sample.findOne({"pos":{$near:[22.1173487,88.0034742]},$maxDistance:100})
null
MongoDB shell 版本:2.4.9 32bit
我使用了错误的语法,我需要在传递给 pos 的字典中传递 $maxDistance
错误
db.kol_sample.find({"pos":{$near:[22.1173487,88.0034742]},$maxDistance:100})
正确
db.kol_sample.find({pos:{$near:[22.1173487,88.0034742],$maxDistance:1/111.2}})
我有一个结构如下的数据库:
{
"_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 参数后,无论我经过多远,它总是 returns null
db.kol_sample.findOne({"pos":{$near:[22.1173487,88.0034742]},$maxDistance:100})
null
MongoDB shell 版本:2.4.9 32bit
我使用了错误的语法,我需要在传递给 pos 的字典中传递 $maxDistance
错误
db.kol_sample.find({"pos":{$near:[22.1173487,88.0034742]},$maxDistance:100})
正确
db.kol_sample.find({pos:{$near:[22.1173487,88.0034742],$maxDistance:1/111.2}})