简体   繁体   English

Mongodb地理空间查询未报告球形包裹错误,但返回了奇怪的结果

[英]Mongodb geo-spatial query not reporting an error on spherical wrapping, but returning a weird result

I have a weird behavior when querying geospatial data. 查询地理空间数据时,我的行为很奇怪。

From the doc : 文档

We don't currently handle wrapping at the poles or at the transition from -180° to +180° longitude, however we detect when a search would wrap and raise an error. 目前,我们不处理极点处或从-180°到+ 180°经度的转折,但是,我们会检测搜索何时会转折并产生错误。

However I have one object at [179,0] and if I query for objects near [-179,0] with a max distance of 0.9, the object is returned and the computed distance is 2 degrees. 但是,我在[179,0]有一个对象,如果我查询[-179,0]附近的对象且最大距离为0.9,则返回该对象,计算出的距离为2度。 No error is raised. 没有错误。

If I query for the same location, but with a max distance of 1.0 the object is not returned and still no error. 如果我查询相同的位置,但最大距离为1.0,则不会返回该对象,并且仍然没有错误。

Is this a bug or do I miss something? 这是一个错误还是我错过了什么? I could not find any reported bug about that on jira. 我在jira上找不到有关此的任何已报告错误。

PRIMARY> version()
version: 2.0.7
PRIMARY> db.runCommand({geoNear:"GeoBug",near:[-179,0],spherical:true,maxDistance:1.0})
{
  "ns" : "mydb.GeoBug",
  "near" : "0100000000000000100010100010100000000000100010100010",
  "results" : [
    {
      "dis" : 0.03490658503988567, (2 degrees)
      "obj" : {
        "_id" : ObjectId("5098e71b744eca2df1b325f2"),
        "location" : {
          "lonlat" : [
            179,
            0
          ]
        }
      }
    }
  ],
  "stats" : {
    "time" : 0,
    "btreelocs" : 0,
    "nscanned" : 2,
    "objectsLoaded" : 1,
    "avgDistance" : 0.03490658503988567,
    "maxDistance" : 0.03490689563235392
  },
  "ok" : 1
}
PRIMARY> db.runCommand({geoNear:"GeoBug",near:[-179,0],spherical:true,maxDistance:0.9})
{
  "ns" : "mydb.GeoBug",
  "near" : "0100000000000000100010100010100000000000100010100010",
  "results" : [ ],
  "stats" : {
    "time" : 0,
    "btreelocs" : 0,
    "nscanned" : 1,
    "objectsLoaded" : 0,
    "avgDistance" : NaN,
    "maxDistance" : 0
  },
  "ok" : 1
}

I've tried this with both 2.0.7 and 2.2.1 and I get some different behavior than you do. 我已经在2.0.7和2.2.1上都尝试过,但是我得到的行为与您不同。

I did this for both versions: 我为两个版本都这样做了:

t = db.test
t.drop()
t.insert({geo: [179,0]})
t.ensureIndex({geo: "2d"})

In 2.0.7, I ran: 在2.0.7中,我运行了:

db.runCommand({geoNear:"test", near:[-179,0], spherical:true, maxDistance:1.0})
db.runCommand({geoNear:"test", near:[-179,0], spherical:true, maxDistance:0.9})

and each returned a result. 并各自返回结果。

However, for 2.2.1, neither search returned a result. 但是,对于2.2.1,两个搜索均未返回结果。 This suggests that there is no wrapping around in 2.2.1 as documented, but there is wrapping around in 2.0.7. 这表明在2.2.1中没有环绕记录,但是在2.0.7中存在环绕。

It's very ridiculous, but try with 'sperical' instead of 'spherical'. 这非常荒谬,但是尝试使用“ sperical”而不是“球形”。

It's working for my case. 它适合我的情况。

I don't know why, and now I'm looking for the answers, but I couldn't find any. 我不知道为什么,现在我正在寻找答案,但找不到任何答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM