codepunkt / mongoose-patch-history

Mongoose plugin that saves a history of JSON patch operations for all documents belonging to a schema in an associated 'patches' collection
MIT License
96 stars 21 forks source link

findOneAndUpdate with options { new: true, rawResult: true } throws Error #69

Closed maxsimych closed 4 years ago

maxsimych commented 4 years ago

When the plugin is added to Model and with that model I call:

const result = await Model.findOneAndUpdate(query, data, {
    new: true,
    rawResult: true
})

Error is throwed: TypeError: document.data is not a function at mongoose-patch-history/lib/index.js:129:111

vinerich commented 4 years ago

Hey @maxsimych ! Could you provide us your plugin configuration? Thanks!

maxsimych commented 4 years ago

versions: node: 14.11.0 mongodb: 3.6.2 mongoose: 5.10.6 mongoose-patch-history: 2.0.0

config: { mongoose, name: 'ModelPatches', trackOriginalValue: true }

vinerich commented 4 years ago

To get things started could you check the below two points?

  1. The issue only appears with the options { new: true, rawResult: true } set? Could you try the different combinations of both parameters and log that here?
  2. Just to be sure you apply the plugin like Model.plugin(patchHistory, config)?

Thanks !

maxsimych commented 4 years ago
  1. Yes, only this combination doesn't work. Separately they work without problem.
  2. Yes, I do the same)
vinerich commented 4 years ago

I think I got you there. @codepunkt will close this issue when PR is merged, shouldn't take too long since it is a small fix. Hope that will do!

If there's anything else feel free to open another issue 😄

codepunkt commented 4 years ago

Merged into master, will be released in next patch release. Until it is, please install directly from GitHub.

Thanks to both of you 👍