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

Multiple geoSpatial indexes in a collection

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.0-rc0
    • Component/s: None
    • ALL
    • Hide

      db.testgeo.insert({name: "New York, NY", loc : { type:"Point", coordinates:[-74.005973,40.714353]}})
      db.testgeo.insert({name: "Los Angles, CA", loc : { type:"Point", coordinates:[-118.243685,34.052234]}})
      db.testgeo.ensureIndex(

      {loc:"2dsphere"}

      )
      db.testgeo.ensureIndex(

      {loc:"2dsphere",name:1}

      )
      db.testgeo.ensureIndex(

      {name:1,loc:"2dsphere"}

      )
      db.testgeo.find({loc:{$near:{$geometry:{type : "Point" ,coordinates :[-74.005973,40.714353]}}}})

      db.runCommand({geoNear: "testgeo",near : {$geometry:

      {type : "Point" ,coordinates :[-74.005973,40.714353]}

      }})
      db.testgeo.aggregate([{$geoNear:{near:[-74.005973, 40.714353 ],distanceField:"dyst"}}])

      Show
      db.testgeo.insert({name: "New York, NY", loc : { type:"Point", coordinates: [-74.005973,40.714353] }}) db.testgeo.insert({name: "Los Angles, CA", loc : { type:"Point", coordinates: [-118.243685,34.052234] }}) db.testgeo.ensureIndex( {loc:"2dsphere"} ) db.testgeo.ensureIndex( {loc:"2dsphere",name:1} ) db.testgeo.ensureIndex( {name:1,loc:"2dsphere"} ) db.testgeo.find({loc:{$near:{$geometry:{type : "Point" ,coordinates : [-74.005973,40.714353] }}}}) db.runCommand({geoNear: "testgeo",near : {$geometry: {type : "Point" ,coordinates :[-74.005973,40.714353]} }}) db.testgeo.aggregate([{$geoNear:{near: [-74.005973, 40.714353 ] ,distanceField:"dyst"}}])

      The documentation at http://docs.mongodb.org/master/core/2dsphere/ states that you can have only one geospatial index per collection. However we can create multiple geospatial indexes

      find with $near works

      geoNear and $geoNear do not work
      "errmsg" : "exception: geoNear command failed:

      { ok: 0.0, errmsg: \"more than one 2dsphere index, not sure which to run geoNear on\" }

      "

            Assignee:
            Unassigned Unassigned
            Reporter:
            rajeXsh Rajesh Khot
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: