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

update on field with geo-index fails with dot-notation if more than 2 elements updated

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.0.1, 2.2.0
    • Component/s: Geo, Write Ops
    • None
    • Fully Compatible
    • ALL

      According to wiki, a geo-spatially indexed field can have more than 2 elements:
      http://www.mongodb.org/display/DOCS/Geospatial+Indexing
      (recommendation is array of 2, but doc/wiki and source code does not strictly forbid a document and more than 2 elements)

      In the case of more than 2 elements (e.g.

      {latitude: x, longitude: y, altitude: z}

      ), an in-place update replacing the whole "loc" sub-document works as expected:

      db.collection.remove()
      db.collection.ensureIndex({loc: '2d'})
      db.collection.insert({_id: 1, loc: {lat: 100, long: 50, alt: 300}})
      db.collection.update({_id: 1}, {$set: {loc: {lat: 110, lon: 60, alt: 310}}})
      

      However, using dot-notation for the update results in error:

      db.collection.update({_id: 1}, {$set: {'loc.lat': 120, 'loc.lon': 70, 'loc.alt': 320 }})
      point not in interval of [ -180, 180 ]
      

      I've traced the error back to the _hash( const BSONObj& o ) in src/mongo/db/geo/2d.cpp line 326, which seems to return the objects in different order (x equals 'alt' in my case).

      The new docs are slightly clearer than the wiki on the issue:
      http://docs.mongodb.org/manual/core/indexes/#geospatial-indexes
      saying: "MongoDB will reject documents that have values in the loc field beyond the minimum and maximum values."

      But the issue remains, that the elements are returned in wrong order and the update tries to assign z to loc.lat.

            Assignee:
            siyuan.zhou@mongodb.com Siyuan Zhou
            Reporter:
            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: