diff --git a/spec/transform.spec.js b/spec/transform.spec.js index c7780ffbd2..91d074a5e6 100644 --- a/spec/transform.spec.js +++ b/spec/transform.spec.js @@ -66,7 +66,7 @@ describe('transformCreate', () => { it('plain', (done) => { var geoPoint = {__type: 'GeoPoint', longitude: 180, latitude: -180}; var out = transform.transformCreate(dummySchema, null, {location: geoPoint}); - expect(out.location).toEqual([180, -180]); + expect(out.location).toEqual({ type: 'Point', coordinates: [ 180, -180 ] }); done(); }); diff --git a/src/ExportAdapter.js b/src/ExportAdapter.js index 821c69cdca..c06bf3e81e 100644 --- a/src/ExportAdapter.js +++ b/src/ExportAdapter.js @@ -479,7 +479,7 @@ ExportAdapter.prototype.smartFind = function(coll, where, options) { } var index = {}; - index[key] = '2d'; + index[key] = '2dsphere'; //TODO: condiser moving index creation logic into Schema.js return coll.createIndex(index).then(() => { // Retry, but just once. diff --git a/src/transform.js b/src/transform.js index 4606b063dd..6818943c7f 100644 --- a/src/transform.js +++ b/src/transform.js @@ -747,21 +747,41 @@ var BytesCoder = { var GeoPointCoder = { databaseToJSON(object) { - return { - __type: 'GeoPoint', - latitude: object[1], - longitude: object[0] + if (GeoPointCoder.isValidGeoJson(object)) { + return { + __type: 'GeoPoint', + latitude: object['coordinates'][1], + longitude: object['coordinates'][0] + } + } else if (GeoPointCoder.isValidLegacyCoordinates(object)) { + return { + __type: 'GeoPoint', + latitude: object[1], + longitude: object[0] + } + } else { + throw 'invalid database object'; } }, + isValidGeoJson(object) { + return (object instanceof Object + && object['type'] == 'Point' + && 'coordinates' in object + && GeoPointCoder.isValidLegacyCoordinates(object['coordinates'])); + }, + + isValidLegacyCoordinates(object) { + return (object instanceof Array + && object.length == 2); + }, + isValidDatabaseObject(object) { - return (object instanceof Array && - object.length == 2 - ); + return GeoPointCoder.isValidGeoJson(object) || GeoPointCoder.isValidLegacyCoordinates(object); }, JSONToDatabase(json) { - return [ json.longitude, json.latitude ]; + return { type: 'Point', coordinates: [ json.longitude, json.latitude ] }; }, isValidJSON(value) {