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

Multiple geoSpatial indexes in a collection

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • 2.6.0-rc0
    • None
    • 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"}}])

    Description

      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\" }

      "

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: