A transaction system for tree documents for mongoose.
Tree document schema:
_id: ObjectId //this (parent) document id
children: // optional array of children
[
{
_id: ObjectId //this child document id or reference to document from another collections.
},
...
]
Tree-transact allow:
- to safely move child subdocuments from one parent document to another;
- to safely add and remove child subdocuments;
- to safely change parent document data.
It is guaranteed that child subdocuments will not multiply and will not disappear. If a database or server error occurs, the documents are automatically restored.
It is possible to add additional fields to both the parent and child subdocuments (name, data, collectionName, etc.). Supported child documents from another collections.
npm install tree-transact -S
see the directory containing this source /example/example1.js
From within the directory containing this source:
npm run example1
From within the directory containing this source:
npm run test
Warning: Continuous tests with random operations - take a few minutes
tran - transaction object
check - value for check child document exists.
Pull requests, issues, and feedback are welcome.