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

Not capturing delete events. #91

Open garg10may opened 2 years ago

garg10may commented 2 years ago

If I am deleting the original document it's not capturing that. Tried using both 'fine' and 'deleteOne' syntax.

  return await ppc.deleteOne({ _id: id });
  return await ppc.find({ _id: id }).remove();
vinerich commented 2 years ago

Hello @garg10may,

I'll try to check that. If it not happens till tomorrow please ping me again here.

Thanks for your feedback!

Am 9. Januar 2022 10:37:55 MEZ schrieb garg10may @.***>:

If I am deleting the original document it's not capturing that. Tried using both 'fine' and 'deleteOne' syntax.

 return await ppc.deleteOne({ _id: id });
 return await ppc.find({ _id: id }).remove();

-- Reply to this email directly or view it on GitHub: https://github.com/codepunkt/mongoose-patch-history/issues/91 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

vinerich commented 2 years ago

@garg10may We have tests for the findOne syntax. Can you try that and report back?

We didn't register deleteOne currently, since I can't merge right away I won't be able to provide that.

vinerich commented 2 years ago

Hey @garg10may are there any updates on this?

garg10may commented 2 years ago

As i understand deleteOne can't be captured since mongodb doesn't provide the same. In other lib also deleteOne is not captured.

vinerich commented 2 years ago

I tried to get a little into it.

Mongoose doc supports capturing of the deleteOne method. However it is a little tricky to implement correctly since it can be a query or a document hook.

With a little time this could be implemented tho.

What is your opinion on the topic?

OriaLogic commented 2 years ago

Hi there,

Doing await record.remove() does not seem to save an entry in the change history collection either. This seems mandatory to me, as I need to know when a record was deleted and by who/what.

Am I mistaken or doing something wrong ? I can't seem to find a pre('remove') in your code.

This could/should be added quickly WDTY ?

Thanks

vinerich commented 2 years ago

@OriaLogic this is not related to the deleteOne issue isn't it? I'd move it to a separate issue then.

But coming to your issue, we are talking about this operation right?