feathers-mongodb-revisions
Feathers MongoDB service with revision support.
This Feathers database adapter extends the basic MongoDB adapter, adding revision support.
Installation
npm install --save mongodb feathers-mongodb-revisions
Usage
This module is used in the same way as other Feathers database adapters, but automatically tracks _revision
metadata.
This adapter currently implements an "embedded revision" data model, however there are numerous ways to model revisions in MongoDB. Future versions of this adapter may introduce other revision models (pull requests gladly accepted).
Revision Metadata
_id: 123 // Resource ID (Mongo ObjectID or as configured) name: 'Resource Name 2' // Arbitrary properties _revision: id: 2 createdAt: '2016-05-09T01:23:45.678Z' history: _id: 123 name: 'Resource Name 1' _revision: id: 1 createdAt: '2016-05-08T01:23:45.678Z'
id
: The_revision.id
property is an auto-incrementing ID.createdAt
: The_revision.createdAt
date will always be overwritten, even if it is supplied. However, if anupdatedAt
property is supplied on the resource, it will be used instead. (TODO: Make this configurable.)history
: An array of previous revisions (omitting the recursivehistory
properties). When retrieving resources, thehistory
property is omitted. (It will be possible to include the complete history in a future version of the adapter.)
Updating Resources
When updating a resource (via either patch
or update
), the current revision ID must be supplied with the resource data. If this ID is missing or does not match the most recent revision, the update will fail.
let service = app let resource = service service
More Documentation
Please refer to the Feathers database adapter documentation for more details or directly at:
- MongoDB - The detailed documentation for the parent MongoDB adapter
- Extending - How to extend a database adapter
- Pagination and Sorting - How to use pagination and sorting for the database adapter
- Querying - The common adapter querying mechanism
Tests
This adapter comes with two test suites. First, launch a MongoDB instance on mongodb://localhost:27017
, and run the adapter tests with npm test
.
A copy of the feathers-mongodb
test suite can also be run with npm run test:feathers-mongodb
, however these will not all pass. The update/patch tests will fail due to the requirement of passing in the current revision ID, which the upstream tests do not pass. It is still good practice to run these tests occasionally in order to keep fidelity with the upstream Feathers MongoDB adapter.