[SERVER-7058] update on field with geo-index fails with dot-notation if more than 2 elements updated Created: 18/Sep/12  Updated: 10/Mar/15  Resolved: 10/Mar/15

Status: Closed
Project: Core Server
Component/s: Geo, Write Ops
Affects Version/s: 2.0.1, 2.2.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Thomas Rueckstiess Assignee: Siyuan Zhou
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
duplicates SERVER-6399 Refactor update() code Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

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.



 Comments   
Comment by Siyuan Zhou [ 10/Mar/15 ]

With update improvements in 2.6, MongoDB preserves the order of the document fields in the above case. Closing as a dup to the original update improvement ticket.

Generated at Thu Feb 08 03:13:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.