Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-2342

$within: {$center} vs. $near and $maxDistance

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.7.6
    • Affects Version/s: 1.7.4
    • Component/s: None
    • None
    • ALL

      Shouldn't these two types of queries return the same results? They don't always. Why not?

      Attached is a zip code database you can use to test.

      Here are two queries:

      > use geo
      > db.zips.find({'loc': {$near:

      {x: 40.752315, y: -73.977842}

      , $maxDistance: 0.01}}).count()
      3

      > db.zips.find({loc: {$within: {$center: [ [40.752315, -73.977842], 0.01 ] }}}).count()
      25

      But...

      > db.zips.find({'loc': {$near:

      {x: 40.752315, y: -73.977842}

      , $maxDistance: 0.011 }}).count()
      26

      > db.zips.find({loc: {$within: {$center: [ [40.752315, -73.977842], 0.011 ] }}}).count()
      26

      If they're supposed to return the same results, why have them both? If they're not, what's sort of meaningful distinction is there between them?

        1. geo.dump
          932 kB
          Kyle Banker

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            kbanker Kyle Banker
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: