mongoose-draft-log

0.0.18 • Public • Published

draft

draft provide log raw data change history and sync new data to use current plugin model collection

Prerequisites

  • nodejs (support async/await)
  • mongodb
  • mongoose

Installing

npm i mongoose-draft-log

Getting Started

const doc = { name: 'ada', age: 23 };
const person = new Person(doc);
const id = person._id;

await person.saveDraft(); // save draft collection

const item = await person.findPendingDraft(); // item.changes: { _id: { new: 5a97a189a72229035767aabd }, age: { new: 23 }, name: { new: 'ada' } }

await person.updateDraft({ t: 2 });

const item2 = await person.findPendingDraft(); // item2.extra {t: 2}

person.age = 20 // no effect

await person.applyDraft(); // update current draft status done. read draft changes new value save person collection

const p = Person.findById(id) // p.age is 23

p.draft() // p.draft() return a draft model, provide mongoose select in draft model

p.age = 20

await p.saveDraft() // changes.age: { new: 20, old: 23 }
await p.applyDraft() // p.age is 20

p.name = 'abc'

await p.saveDraft()
await p.discardDraft(); // remove all model_id(p._id) = p._id. model = 'person' status = 'pending' data. and update p.draft_status = done

Running the tests

npm i && npm test

Authors

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i mongoose-draft-log

Weekly Downloads

0

Version

0.0.18

License

ISC

Unpacked Size

14.7 kB

Total Files

6

Last publish

Collaborators

  • pagewang