Skip to content
This repository was archived by the owner on Apr 15, 2023. It is now read-only.

not working with findOneAndUpdate with $push #51

@Mobasher-NetLinks

Description

@Mobasher-NetLinks

I have the following query
myModel.findOneAndUpdate({_id: ID},{$push: {myField: myData}},{$new: true})
But pre findOneAndUpdate not work and error occur in its integration with schema:

let options = {
  diffOnly: true,
  metadata: [
    {key: 'user', value: function(origin, d){
      let createdAt = new Date(d.createdAt).getTime();
      let updatedAt = new Date(d.updatedAt).getTime;
      if (createdAt < updatedAt || !operation) {
        operation = 'u';
      }
      return {
        id: operation === 'i' ? d.createdBy.id : d.updatedBy.id,
        firstName: operation === 'i' ? d.createdBy.firstName : d.updatedBy.firstName,
        lastName: operation === 'i' ? d.createdBy.lastName : d.updatedBy.lastName
      }
    }}
  ]
};
schema.plugin(mongooseHistory, options);

Error is in d.createdBy, because if I console d, it shows following data:
{ updatedAt: 2019-01-30T08:52:43.770Z, __v: undefined }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions