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 = ;var query = ;// => { $set: { b: 'world' }, $unset: { a: 1 }}
Or with a filter (see cloudup/mongo-minify for more examples)
var query = ;// => { $set: { a: 2 }} ## Note on arraysBy default arrays will not diffed This is not ideal when dealing with nested documentsInstead of trying to implement a complex diffing solution for these cases `mongo-update`allows you to define a prefix on your queries ```jsvar 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