Update json
Hi,
my document like:
{ email: "[email protected]", status: { active: true, created: "20170106" } }
If I use update method to status.active then sqlagent rewrite the full status (delete created field). How can I update only active field?
Thank you, David
Hi, i think that builder doesn't support updating of a property inside of nested object.
If you are using this
builder.set({ status: { active: false }});
or this
builder.set('status', { active: false });
then it will replace whole status object since it creates following query
{ $set: { status: { active: false }}} this is like doing status = { active: false }
but you need either
{ $set: { 'status.active': false }} this is like doing status.active = false; so other props of status object remains the same
or
{ status: { $set: { active: false }}}
This might do what you need
builder.raw({ status: { $set: { active: false }}});
or
builder.raw({ $set: { 'status.active': false }});
or
builder.set('status.active': false);
Hope it helps.
builder.set('status.active': false); working fine :)
Thank you!