Skip to content

Nested Date type attributes are saved differently at different levels #7575

Closed
@hariprasadiit

Description

@hariprasadiit

New Issue Checklist

Issue Description

If we try to create an object with below code

const myObj = new Parse.Object('Company3');
await myObj.save({
  prop1: 'test1',
  prop2: {
    test: {
      date: new Date()
    }
  },
  prop3: {
    date: new Date()
  }
}, {useMasterKey: true});

This is how the saved object in mongo DB looks like

{
  "_id": "5DTIqZcZv9fhbHu0qTZq",
  "prop2": {
    "test": {
      "date": {
        "__type": "Date",
        "iso": "2021-09-14T14:50:37.303Z"
      }
    }
  },
  "prop3": {
    "date": {
      "$date": "2021-09-14T14:50:37.303Z"
    }
  },
  "prop1": "test1",
  "_created_at": {
    "$date": "2021-09-14T14:50:38.108Z"
  },
  "_updated_at": {
    "$date": "2021-09-14T14:50:38.108Z"
  }
}

prop2.test.date is saved as JSON object instead of $date object while prop3.date is properly saved.
This breaks date queries

Steps to reproduce

  1. Create new object with below code
const myObj = new Parse.Object('Company3');
await myObj.save({
  prop1: 'test1',
  prop2: {
    test: {
      date: new Date()
    }
  },
  prop3: {
    date: new Date()
  }
}, {useMasterKey: true});
  1. Observe different date types at different levels in mongoDB Compass

Actual Outcome

{
  "_id": "5DTIqZcZv9fhbHu0qTZq",
  "prop2": {
    "test": {
      "date": {
        "__type": "Date",
        "iso": "2021-09-14T14:50:37.303Z"
      }
    }
  },
  "prop3": {
    "date": {
      "$date": "2021-09-14T14:50:37.303Z"
    }
  },
  "prop1": "test1",
  "_created_at": {
    "$date": "2021-09-14T14:50:38.108Z"
  },
  "_updated_at": {
    "$date": "2021-09-14T14:50:38.108Z"
  }
}

Expected Outcome

{
  "_id": "5DTIqZcZv9fhbHu0qTZq",
  "prop2": {
    "test": {
      "date": {
        "$date": "2021-09-14T14:50:37.303Z"
      }
    }
  },
  "prop3": {
    "date": {
      "$date": "2021-09-14T14:50:37.303Z"
    }
  },
  "prop1": "test1",
  "_created_at": {
    "$date": "2021-09-14T14:50:38.108Z"
  },
  "_updated_at": {
    "$date": "2021-09-14T14:50:38.108Z"
  }
}

Environment

Server

  • Parse Server version: 4.10.3
  • Operating system: Mac OS
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 4.4.4
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Local

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): Javascript
  • SDK version: 3.3.0

Old issue related to this #6840

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:breakingBreaking change requires major version increment and `BREAKING CHANGE` commit messagestate:releasedReleased as stable versionstate:released-alphaReleased as alpha versionstate:released-betaReleased as beta versiontype:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions