npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

feathers-mongodb-revisions

v1.0.0

Published

Feathers MongoDB service with revision support.

Downloads

7

Readme

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 an updatedAt property is supplied on the resource, it will be used instead. (TODO: Make this configurable.)
  • history: An array of previous revisions (omitting the recursive history properties). When retrieving resources, the history 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.service('resources')

let resource = service.get(1)

service.patch(service.id, {
  name: 'updated name',
  _revision: {
    id: resource._revision.id
  }
})

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.