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

Query: Cannot hint with geo $near

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.5.5
    • Component/s: Querying
    • Labels:
      None
    • ALL
    • Hide
      function getRandomLat(seed) {
      	lat=Math.random(seed)*56666%180;
      	if (Math.round(Math.random(seed)) == 0) {
      		lat=lat*-1;
      	}
      	return lat;
      }
      
      function getRandomLng(seed) {
      	lng=Math.random(seed)*56666%90;
      	if (Math.round(Math.random(seed)) == 0) {
      		lng=lng*-1;
      	}
      	return lng;
      }
      
      for (i=0; i< 100; i++) {
      	doc = {a: i%5, b: i%9, c: i%7,
      		geo: {lng : getRandomLng(i), lat : getRandomLat(i)}};
             t.insert(doc)
      }
      t.ensureIndex({a:1});
      t.ensureIndex({geo: "2d"});
      t.find({a:4, geo: {$near: [getRandomLng(50),getRandomLat(50)]}}).explain().cursor;
      t.find({a:4, geo: {$near: [getRandomLng(50),getRandomLat(50)]}}).hint({a:1}).explain().cursor
      
      
      Show
      function getRandomLat(seed) { lat=Math.random(seed)*56666%180; if (Math.round(Math.random(seed)) == 0) { lat=lat*-1; } return lat; } function getRandomLng(seed) { lng=Math.random(seed)*56666%90; if (Math.round(Math.random(seed)) == 0) { lng=lng*-1; } return lng; } for (i=0; i< 100; i++) { doc = {a: i%5, b: i%9, c: i%7, geo: {lng : getRandomLng(i), lat : getRandomLat(i)}}; t.insert(doc) } t.ensureIndex({a:1}); t.ensureIndex({geo: "2d"}); t.find({a:4, geo: {$near: [getRandomLng(50),getRandomLat(50)]}}).explain().cursor; t.find({a:4, geo: {$near: [getRandomLng(50),getRandomLat(50)]}}).hint({a:1}).explain().cursor

      Specifying a hint when doing a geo $near query fails with an error:

      t.find({a:4, geo: {$near: [getRandomLng(50),getRandomLat(50)]}}).hint({geo: 1}).explain().cursor
      2014-02-05T15:59:44.687-0500 error: {
      	"$err" : "Unable to execute query: error processing query: ns=test.filters limit=0 skip=0\nTree: $and\n    a == 4.0\n    GEONEAR  field=geo maxdist=1.79769e+308 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error: bad hint",
      	"code" : 17007
      > t.find({a:4, geo: {$near: [getRandomLng(50),getRandomLat(50)]}}).hint({a:1}).explain().cursor
      2014-02-05T15:54:41.638-0500 error: {
      	"$err" : "Unable to execute query: error processing query: ns=test.filters limit=0 skip=0\nTree: $and\n    a == 4.0 First: 0 notFirst: full path: a\n    GEONEAR  field=geo maxdist=1.79769e+308 isNearSphere=0 First: notFirst: full path: geo\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query",
      	"code" : 17007
      } at src/mongo/shell/query.js:131
      > t.find({a:4, geo: {$near: [getRandomLng(50),getRandomLat(50)]}}).explain().cursor
      GeoSearchCursor
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            jonathan.abrahams Jonathan Abrahams
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: