{"repo":"codepunkt/mongoose-patch-history","free":true,"listed":false,"github":"https://github.com/codepunkt/mongoose-patch-history","clone":"git clone https://github.com/codepunkt/mongoose-patch-history.git","description":"Mongoose plugin that saves a history of JSON patch operations for all documents belonging to a schema in an associated 'patches' collection","language":"JavaScript","stars":96,"topics":["mongoose","mongodb","schema","json","json-patch","history","changes","changeset"],"license":"MIT","category":"data-pipelines","readme_excerpt":"Mongoose Patch History is a mongoose plugin that saves a history of JSON Patch operations for all documents belonging to a schema in an associated \"patches\" collection. Installation $ npm install mongoose-patch-history Usage To use mongoose-patch-history for an existing mongoose schema you can simply plug it in. As an example, the following schema definition defines a Post schema, and uses mongoose-patch-history with default options: mongoose-patch-history will define a schema that has a ref field containing the ObjectId of the original document, a ops array containing all json patch operations and a date field storing the date where the patch was applied. Storing a new document Continuing the previous example, a new patch is added to the associated patch collection whenever a new post is added to the posts collection: Updating an existing document mongoose-patch-history also adds a static field Patches to the model that can be used to access the patch model associated with the model, for example to query all patches of a document. Whenever a post is edited, a new patch that reflects the update operation is added to the associated patch collection: Rollback to a specific patch Documents have a rollback method that accepts the ObjectId of a patch doc and sets the document to the state of that patch, adding a new patch to the history. Injecting data Further the rollback method accepts a data object which is injected into the document. Rollback without saving To rollback the doc","default_branch":null,"files":null,"tree":[],"storefront":"/r/codepunkt","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/codepunkt/mongoose-patch-history/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}