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

mongoose-plugin-modified

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-plugin-modified

Mongoose.js plugin to capture document modification timestamp with optional user identifier

  • 1.4.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

mongoose-plugin-modified

Codeship Status for CentralPing/mongoose-plugin-modified Build Status Code Climate for CentralPing/mongoose-plugin-modified Dependency Status for CentralPing/mongoose-plugin-modified

A mongoose.js plugin to capture document updates with timestamp and optional user identifier.

The modification date is updated pre-validation if a monitored field has been modified

Installation

npm i --save mongoose-plugin-modified

API Reference

Example

var modifiedPlugin = require('mongoose-plugin-modified');
var schema = Schema({...});
schema.plugin(modifiedPlugin[, OPTIONS]);

mongoose-plugin-modified~options

Kind: inner property of mongoose-plugin-modified

ParamTypeDefaultDescription
[options]object
options.optionKeystring"modified"the path options key to mark paths for inclusion in monitoring for modification. If no paths are tagged, document modification is monitored.
[options.date]objectoptions for configuring the path for storing the date.
options.date.pathstring"modified.date"the path for storing the modified date.
options.date.optionsobjectproperty options to set (type will always be Date). (e.g. {select: false})
[options.by]objectoptions for configuring the path for storing the modifier.
options.by.pathstring"modified.by"the path for storing the document modifier.
options.by.refstringthe reference model to use (e.g. {by: {ref: 'ModelRefName'}})
options.by.optionsobjectproperty options to set (if not a reference the type will always be String). (e.g. {select: false})

Examples

With Monitoring Entire Document

var modifiedPlugin = require('mongoose-plugin-modified');
var schema = Schema({foo: String});
schema.plugin(modifiedPlugin);

var Foo = mongoose.model('Foo', schema);
var foo = Foo.findOne(); // foo.modified --> {}
foo.foo = 'My update'; // foo.modified --> {}
foo.save(); // foo.modified --> {date: 'Wed May 05 2015 12:05:50 GMT-0400 (EDT)'}

With Monitoring Selected Fields

var modifiedPlugin = require('mongoose-plugin-modified');
var schema = Schema({
  foo: {
    type: String,
    modified: true // indicates to monitor this field for modification
  },
  bar: {
    type: String
  }
});
schema.plugin(modifiedPlugin);

var Foo = mongoose.model('Foo', schema);
var foo = Foo.findOne(); // foo.modified --> {}
foo.foo = 'My update'; // foo.modified --> {}
foo.save(); // foo.modified --> {date: 'Wed May 05 2015 12:05:50 GMT-0400 (EDT)'}

foo.bar = 'My other update'; // foo.modified --> {date: 'Wed May 05 2015 12:05:50 GMT-0400 (EDT)'}
foo.save(); // foo.modified --> {date: 'Wed May 05 2015 12:05:50 GMT-0400 (EDT)'}
            // modified.date is not updated

License

Apache 2.0

Keywords

FAQs

Package last updated on 24 Apr 2016

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