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

Updating object - Bug or WAD?

Open stefanwalther opened this issue 5 years ago • 1 comments

Hi,

I am having the following situation:

  • I have an object with unknown structure (defined by an external system)
  • Let's say it looks as follows
let schema = mongoose.Schema(
    {
      name: 'string',
      size: 'string',
      infos: {
        type: Object,
        required: true,
        default: {}
      }
    }
  );
  schema.plugin(HistoryPlugin);
  let Tank = mongoose.model('tankExtended', schema);

If I now patch the model, the history is always saved, regardless infos has changed or not.

Do you consider this to be a WAD (e.g. I should use a subdocument), or should some deep-checking happening here?

Thx a lot for your answer & this great project!

stefanwalther avatar Oct 21 '19 21:10 stefanwalther

You should check if the option noDiffSave and noDiffSaveMethods are true. If this is the case, change the noDiffSave to false.

  noDiffSave: false, // If true save event even if there are no changes
  noDiffSaveOnMethods: ['delete'], // If a method is in this list, it saves history even if there is no diff.

Masquerade-Circus avatar May 17 '20 14:05 Masquerade-Circus