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

Cannot perform an `add` operation at the desired path #68

Closed intermx-reddysai closed 2 years ago

intermx-reddysai commented 3 years ago

NodeJS: 12.16.3 npm: 6.14.4 OS: ubuntu

I'm trying to read the initial patch record with help of rollback but it is throwing an error like,

Cannot perform an `add` operation at the desired path
name: OPERATION_PATH_CANNOT_ADD

doc = await doc.rollback(patches[0]._id.toString(), {}, false);

How do I read read the initial (operation: { op: 'add', ...) record?

codepunkt commented 3 years ago

@vinerich any ideas?

intermx-reddysai commented 3 years ago

I have three patch records with the same reference Id, to get the first and/or second patch version, it is not working with the rollback.

vinerich commented 3 years ago

@codepunkt shouldn't be something with the newest version. (I hope)

@intermx-reddysai can you show us the three patch records and the document you try to rollback? Edit: Plugin config would be nice too! Which options are you using?

Thanks!

vinerich commented 3 years ago

Hey @intermx-reddysai any news on this? Did you fix your error? Let us know!

intermx-reddysai commented 3 years ago

That was because of ObjectId, it is not working properly on ObjectId.

I had a model field with array of mongoose object Ids. If I update any of the object id, it is not working as expected.

vinerich commented 3 years ago

Thanks for your response! Could you share a few more details with us so we can look into it?

  1. Are you updating the array through push/pop operations or with save?
  2. Which plugin config are you using?
  3. What exactly is not working as expected? I mean what is happening that is different?

Thanks!