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

Improve error message for 2dsphere $near query with extra fields in geo predicate

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.0-rc2
    • Affects Version/s: 2.6.0-rc0
    • Component/s: Geo
    • None
    • Fully Compatible
    • ALL

      2dsphere $near queries return the unhelpful message "not handled: $near" on queries if extra fields are erroneously included in the geo predicate:

      > db.poiConcat.ensureIndex({l: "2dsphere"})
      WriteResult({ "nInserted" : 1 })
      > db.poiConcat.insert({l: {type: 'Point', coordinates: [ -73.56, 45.49 ] }, ts: 'amenity=pub'})
      WriteResult({ "nInserted" : 1 })
      > db.poiConcat.find( { l: { '$near': { '$geometry': { type: 'Point', coordinates: [ -73.56, 45.48] } } }, 'ts': 'amenity=pub' } ).limit(1).pretty();
      {
      	"_id" : ObjectId("530f897fe931f3ea33c3fca2"),
      	"l" : {
      		"type" : "Point",
      		"coordinates" : [
      			-73.56,
      			45.49
      		]
      	},
      	"ts" : "amenity=pub"
      }
      > db.poiConcat.find( { l: { '$near': { '$geometry': { type: 'Point', coordinates: [ -73.56, 45.48] } }, foo: 'bar' }, 'ts': 'amenity=pub' } ).limit(1).pretty();
      error: {
      	"$err" : "Can't canonicalize query: BadValue not handled: $near",
      	"code" : 17287
      }
      

      This error message needs to be improved, particularly because the below query form was a (undocumented but) valid way to specify $maxDistance for a $near query in 2.4. This form is being broken for 2.6, but users who use the invalid form need better diagnostics.

      > db.poiConcat.find( { l: { '$near': { '$geometry': { type: 'Point', coordinates: [ -73.56, 45.48] } }, $maxDistance: 100 }, 'ts': 'amenity=pub' } ).limit(1).pretty();
      error: {
      	"$err" : "Can't canonicalize query: BadValue not handled: $near",
      	"code" : 17287
      }
      

      Original ticket description:

      With 2.4.x (and I also believe 2.5.5), I could run the following query:

      db.poiConcat.find( { l: { '$near': { '$geometry': { type: 'Point', coordinates: [ -73.56, 45.49 ] } }, '$maxDistance' : 2500 }, 'ts': 'amenity=pub' } ).limit(1).pretty();
      

      With 2.6.0rc0, this now returns:

      error: {
      	"$err" : "Can't canonicalize query: BadValue not handled: $near",
      	"code" : 17287
      }
      

      Steps to reproduce: No data or indexes have to be created. Just run this:

      derick@whisky:~ $ install/mongodb-linux-x86_64-2.6.0-rc0/bin/mongo foo
      MongoDB shell version: 2.6.0-rc0
      connecting to: foo
      Server has startup warnings: 
      2014-02-27T09:25:14.228-0500 ** WARNING: --rest is specified without --httpinterface,
      2014-02-27T09:25:14.228-0500 **          enabling http interface
      > db.poiConcat.find( { l: { '$near': { '$geometry': { type: 'Point', coordinates: [ -73.56, 45.49 ] } }, '$maxDistance' : 2500 }, 'ts': 'amenity=pub' } ).limit(1).pretty();
      error: {
      	"$err" : "Can't canonicalize query: BadValue not handled: $near",
      	"code" : 17287
      }
      

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            derick Derick Rethans
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: