diff --git a/spec/MongoTransform.spec.js b/spec/MongoTransform.spec.js index f0bb6ec4d9..c432e7960e 100644 --- a/spec/MongoTransform.spec.js +++ b/spec/MongoTransform.spec.js @@ -293,6 +293,32 @@ describe('parseObjectToMongoObjectForCreate', () => { expect(output.double).toBe(Number.MAX_VALUE); done(); }); + + it('Date object where iso attribute is of type Date', (done) => { + var input = { + ts : { __type: 'Date', iso: new Date('2017-01-18T00:00:00.000Z') } + } + var output = transform.mongoObjectToParseObject(null, input, { + fields : { + ts : { type : 'Date' } + } + }); + expect(output.ts.iso).toEqual('2017-01-18T00:00:00.000Z'); + done(); + }); + + it('Date object where iso attribute is of type String', (done) => { + var input = { + ts : { __type: 'Date', iso: '2017-01-18T00:00:00.000Z' } + } + var output = transform.mongoObjectToParseObject(null, input, { + fields : { + ts : { type : 'Date' } + } + }); + expect(output.ts.iso).toEqual('2017-01-18T00:00:00.000Z'); + done(); + }); }); describe('transformUpdate', () => { diff --git a/src/Adapters/Storage/Mongo/MongoTransform.js b/src/Adapters/Storage/Mongo/MongoTransform.js index e91abbb563..030f7806b5 100644 --- a/src/Adapters/Storage/Mongo/MongoTransform.js +++ b/src/Adapters/Storage/Mongo/MongoTransform.js @@ -726,6 +726,11 @@ const nestedMongoObjectToNestedParseObject = mongoObject => { return BytesCoder.databaseToJSON(mongoObject); } + if (mongoObject.hasOwnProperty('__type') && mongoObject.__type == 'Date' && mongoObject.iso instanceof Date) { + mongoObject.iso = mongoObject.iso.toJSON(); + return mongoObject; + } + return _.mapValues(mongoObject, nestedMongoObjectToNestedParseObject); default: throw 'unknown js type';