diff --git a/spec/MongoTransform.spec.js b/spec/MongoTransform.spec.js index a3c61214a8..ade0b0d4d0 100644 --- a/spec/MongoTransform.spec.js +++ b/spec/MongoTransform.spec.js @@ -429,6 +429,20 @@ describe('parseObjectToMongoObjectForCreate', () => { done(); }); + it('untransforms a null expiresAt to null, not epoch (#7576)', () => { + const output = transform.mongoObjectToParseObject('Document', { expiresAt: null }, { + fields: { expiresAt: { type: 'Date' } }, + }); + expect(output.expiresAt).toBeNull(); + }); + + it('untransforms a null lastUsed to null, not epoch (#7576)', () => { + const output = transform.mongoObjectToParseObject('Document', { lastUsed: null }, { + fields: { lastUsed: { type: 'Date' } }, + }); + expect(output.lastUsed).toBeNull(); + }); + it('object with undefined nested values', () => { const input = { _id: 'vQHyinCW1l', diff --git a/src/Adapters/Storage/Mongo/MongoTransform.js b/src/Adapters/Storage/Mongo/MongoTransform.js index 0fd13017b3..7e16c53a89 100644 --- a/src/Adapters/Storage/Mongo/MongoTransform.js +++ b/src/Adapters/Storage/Mongo/MongoTransform.js @@ -1179,11 +1179,14 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => { break; case 'expiresAt': case '_expiresAt': - restObject['expiresAt'] = Parse._encode(new Date(mongoObject[key])); + // A cleared date is stored as null; keep it null instead of coercing to epoch (#7576) + restObject['expiresAt'] = + mongoObject[key] === null ? null : Parse._encode(new Date(mongoObject[key])); break; case 'lastUsed': case '_last_used': - restObject['lastUsed'] = Parse._encode(new Date(mongoObject[key])).iso; + restObject['lastUsed'] = + mongoObject[key] === null ? null : Parse._encode(new Date(mongoObject[key])).iso; break; case 'timesUsed': case 'times_used':