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

Geo Query $center with "NaN" coordinate does not error

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.0.0-rc9, 3.1.0
    • Affects Version/s: None
    • Component/s: Geo
    • Labels:
    • Fully Compatible
    • ALL

      Currently, a 2dsphere-indexed collection has the following behavior:

      > db.geo.ensureIndex({geo: "2dsphere"});
      > db.geo.insert({geo:{ type: "Point", coordinates: [ -73.97, 40.77 ] }})
      > db.geo.findOne({geo:{ "$geoWithin" : { "$centerSphere" : [ [ NaN, 4 ], Infinity ] } }});
      2015-01-15T16:35:01.239-0500 I QUERY    Error: error: {
      	"$err" : "Can't canonicalize query: BadValue longitude/latitude is out of bounds, lng: nan lat: 4",
      	"code" : 17287
      }
          at Error (<anonymous>)
          at DBQuery.next (src/mongo/shell/query.js:259:15)
          at DBCollection.findOne (src/mongo/shell/collection.js:187:22)
          at (shell):1:8 at src/mongo/shell/query.js:259
      

      Which makes sense! However, if instead of using $centerSphere we use $center as the query specifier:

      > db.geo.findOne({geo:{ "$geoWithin" : { "$center" : [ [ NaN, 4 ], Infinity ] } }});
      null
      

      I think that the bad lat/long should return an error similar to the one for $centerSphere instead of null for the $center specifier.

      Similar behavior occurs when Infinity or -Infinity is passed as the lat/long for the $center and $centerSphere specifiers: it returns null for $center and an error for $centerSphere.

            Assignee:
            siyuan.zhou@mongodb.com Siyuan Zhou
            Reporter:
            amalia.hawkins@10gen.com Amalia Hawkins
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: