node-sqlagent icon indicating copy to clipboard operation
node-sqlagent copied to clipboard

Update json

Open dacrhu opened this issue 9 years ago • 2 comments

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

dacrhu avatar Oct 22 '17 16:10 dacrhu

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.

molda avatar Oct 22 '17 19:10 molda

builder.set('status.active': false); working fine :)

Thank you!

dacrhu avatar Oct 22 '17 21:10 dacrhu