mongoose-history-plugin icon indicating copy to clipboard operation
mongoose-history-plugin copied to clipboard

FindOneAndUpdate does not create history

Open mayerlench opened this issue 5 years ago • 5 comments

mayerlench avatar Oct 02 '19 14:10 mayerlench

hello,

old issue but today I'm doing this:

<Schema Name>.post('findOneAndUpdate', async function () {
  const docToUpdate = await this.model.findOne(this.getQuery());
  docToUpdate.__history = {
    event: 'updated',
  };
  await docToUpdate.save();
});

I'll try to add this into the plugin

joshrezende avatar Aug 25 '20 23:08 joshrezende

Essa solução suporta o uso de transações do Mongo?

saviocamacam avatar Sep 05 '20 18:09 saviocamacam

any update here? can someone confirm if @joshrezende's suggestion works?

kushalarora92 avatar Feb 23 '21 13:02 kushalarora92

@kushalarora92 it works but isn't pretty i'm using in production

joshrezende avatar Mar 01 '21 16:03 joshrezende

@saviocamacam vai depender da transacao que voce fizer, se tiver um hook para ela vai funcionar sim, mas teria que testar

joshrezende avatar Mar 01 '21 16:03 joshrezende