New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mongo-diff-update

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-diff-update

Diff two objects and return a MongoDB update query,but unset missing keys

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
37
5.71%
Maintainers
1
Weekly downloads
 
Created
Source

mongo-diff-update

Diff two objects and return a MongoDB update query. Useful for reducing the size of your queries. same as mongo-update,but unset missing keys.

Installation

$ npm install mongo-diff-update

Example

var update = require('mongo-diff-update');
var query = update({ a: 'hello' }, { b: 'world', a: null });
// => { $set: { b: 'world' }, $unset: { a: 1 }}

Or with a filter (see cloudup/mongo-minify for more examples)

var query = update({ a: 1, b: 2 }, { a: 2, b: 3 }, { a: 1 });
// => { $set: { a: 2 }}

## Note on arrays
By default, arrays will not diffed. This is not ideal when dealing with nested documents.
Instead of trying to implement a complex diffing solution for these cases, `mongo-update`
allows you to define a prefix on your queries.

```js
var child = { age: 10 };
var parent = { children: [child] };

var query = update(child, { age: 20 }, 'children.$');
// => { $set: { 'children.$.age': 20 }}

db.update({ 'children.age': 10 }, query);

License

MIT

FAQs

Package last updated on 16 Sep 2014

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