Can I remove the content of a field while merging?


I have an object Foo.make({id:‘bar’, a:1, b:2, msg:‘blabla’}) that is persisted.
I would like to merge it with Foo.make({id:‘bar’, a:2, b:3, msg:null})
“msg” field remains present, tried empty string instead of null without success.



Specify the fields that should be merged in the MergeSpec, which is the optional second argument to merge():

Foo.merge({id: ‘bar’, a: 2, b: 3, msg: null}, {include: “a, b, msg”});

1 Like


Another option is to use the 2 object version of upsert

Foo.upsert({id: ‘bar’, a: 2, b: 3}, {id: ‘bar’, msg: ‘oldVal’})

basically the merge/upsert cannot differentiate between a “missing” value and a “null” value



It seems cumbersome to have to figure out the old value, I prefer the merge+include version from @henry.hsieh