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

Bug: With the plugin, updateOne hangs, if nothing was found #71

Closed maxsimych closed 3 years ago

maxsimych commented 3 years ago

If nothing was found with updateOne, (same for update and updateMany) query just hangs without response.

When I turn off the plugin, I get correct result from the query: { n: 0, nModified: 0, ok: 1 }

versions: node: 14.11.0 mongodb: 3.6.2 mongoose: 5.10.6 mongoose-patch-history: the version from github master

config:

Schema.plugin(patchHistory, {
  mongoose, name: 'ModelPatches', trackOriginalValue: true, removePatches: false
})
vinerich commented 3 years ago

Here we go again :D Thanks for the report.

This should be covered by testing but I think I'll have to include a few more versions.

vinerich commented 3 years ago

Just to keep you updated. With a newer mongoose version this behaviour is indeed happening over all node versions. I'll need to find out what causes that odd behaviour, might take a while.

Else, if you would like to help out, you can try to pin down the specific minor mongoose version. Only thing I can say is that it is somewhere between 5.6 and 5.10.

maxsimych commented 3 years ago

Checked! It works in 5.9.6 But stops to work in 5.9.7

maxsimych commented 3 years ago

@vinerich hello, any news?)

vinerich commented 3 years ago

@maxsimych Thanks for bumping! It must've slipt through.

Somewhere along the versions 5.9 to 5.10 several changes where introduced:

So I changed the nModified check to include the new upserted property and am calling next() to return.

Will write PRs and then you should be good to go.

vinerich commented 3 years ago

@codepunkt I know time is spare. Just want to bump the PR if you got the time.

codepunkt commented 3 years ago

@vinerich you should have contributor permissions - atleast I sent out an invite 😉

vinerich commented 3 years ago

@codepunkt I should indeed have, if I didn't forgot it about the new years. Invitation is expired, can you resend it? I'll accept this time :D Thanks.