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

$box should be able to use a 2dsphere query if available and valid coords

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.5.5
    • Component/s: Geo
    • None

      In the following test case - I'd expect the $box query to be able to use the 2dsphere index rather than just a basic cursor.

      db.geo.drop()
      db.geo.insert( { type: "house", loc : { type : "Point", coordinates : [ 71.0603, 42.3583 ] } })
      db.geo.insert( { type: "flat",  loc : { type : "Point", coordinates : [ 87.6500, 41.8500 ] } })
      
      db.geo.ensureIndex({loc: "2dsphere", type: 1});
      
      // Query using $box
      db.geo.find({loc: {
          $geoWithin: {
              $box: [[-180, -90], [180, 90]]
          }
      }, type: "house"}).explain()
      

      Essentially the query is the same as - which will use the 2dsphere index

      db.geo.find( { loc :
        { $geoWithin :
          { $geometry :
            { type : "Polygon" ,
              coordinates : [[ [-180, -90], [180, -90], [180, 90], [-180, -90] ] ]
        } } },
        type: "house" } ).explain()
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            ross@mongodb.com Ross Lawley
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: