Mongo update operators on regular objects

this might sound strange but I’d like to use mongo style operations on regular objects. Specifically, the update operators like $set, $push, etc.

Something like

sourceObject = {foo: {bar: false}}
mUpdate(sourceObject, {$set {{'foo.bar': 'baz'}})

// sourceObject is now {foo: {bar: 'baz'}}

Is there an easy way to accomplish this?

minimongo can probably handle this; haven’t tried it though.

meteor add minimongo

then try:

var sourceObject = {foo: {bar: false}}
var operator = {$set: {'foo.bar': 'baz'}}
LocalCollection._modify(sourceObject, operator);
console.log(sourceObject)
// {foo: {bar: 'baz'}}
3 Likes

Perfect! Works like a charm.