Socket
Book a DemoInstallSign in
Socket

mongo-diff

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-diff

Perform a diff between two objects expressed as MongoDB operations

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
2
Created
Source

mongo-diff

Component to perform a diff between two objects expressed as MongoDB operations.

Example

var diff = require('mongo-diff');

// diff two arrays using set strategy
diff(['a', 'b', 'c'], ['b', 'c', 'a'])

/*
[
  ['pull', 'a'],
  ['push', 'a']
]
*/

Strategies

auto

diff('a', null)
// [['unset', 1]]

diff(1, 5)
// [['inc', 4]]

val(a, b)

diff.val('a', 'b')
// [['set', 'b']]

diff.val('a', null)
// [['unset', 1]]

Expresses differences as $set or $unset.

inc(a, b, opts)

diff.inc(5, 8, { interval: 1 })
// [['inc', 1], ['inc', 1], ['inc', 1]]

Options:

  • interval increment interval. If null the interval defaults to the difference between the numbers (null)

Expresses differences between numbers in terms of $inc operations.

ordered_set(a, b)

diff.ordered_set([], ['a']);
// [['push', 'a']]

Expresses the difference between arrays as a series of $pull / $push operations. Useful to match differences on arrays that are used with the $addToSet MongoDB operation.

TODO

  • More strategies
  • Ordered set indexOf should use deep matching for object/array support

FAQs

Package last updated on 12 Mar 2015

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