Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@syntropy/mongoose-document-versioner

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@syntropy/mongoose-document-versioner

Force version to increment every time you update or save a mongoose document

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

Mongoose Document Versioner

This module sets a document version key that is incremented any time you save or update a document. This is useful for detecting version conflicts.

Increments version on the following pre hooks:

  • findOneAndUpdate
  • updateOne
  • updateMany
  • update
  • save

Note: Model.findByIdAndUpdate() calls the findOneAndUpdate hook.

Usage

const versionerPlugin = require('mongoose-document-versioner');

const schema = new mongoose.Schema({ /* .... */ });
schema.plugin(versionerPlugin);
const Model = mongoose.model('Model', schema);

/* EXAMPLES */

Model.update({attr: 'foo'}, {attr: 'bar'}, {multi: true});
/*
 * mongo query:
 * model.update(
 *   { attr: 'foo' },
 *   { '$inc': { version: 1 }, '$set': { attr: 'bar' } },
 *   { multi: true }
 * )
 */

Model.findOneAndUpdate({attr: 'foo'}, {attr: 'bar'});
/*
 * mongo query:
 * model.findAndModify(
 *   { attr: 'foo' },
 *   { '$inc': { version: 1 }, '$set': { attr: 'bar' } },
 *   { new: false, upsert: false }
 * )
 */

Keywords

FAQs

Package last updated on 09 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc