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.
- duplicates
-
SERVER-6399 Refactor update() code
- Closed