In my Angular fullstack
project I try to update a project adding a new sub-document to it. When checking my req.body
before merging it all looks as it should. However after the merge the updated document has added a new sub-document as it should, the only problem is that this new document is a clone of an already existing one, instead of the one it should have been.
the _.merge
is from lodash
the code:
console.log('');
console.log('notes before merging : ', entry.notes);
console.log('');
console.log('body.notes before merging : ', req.body.notes);
var updated = _.merge(entry, req.body);
console.log('');
console.log('notes after merging : ', updated.notes);
And my console result when running the code:
notes before merging :
[
{
content: '<p>testing</p>',
date: Thu Apr 16 2015 10:14:44 GMT+0200 (Rom, sommertid),
writer: 55193679026666b00554d00e,
_id: 552f6f7435828478156f6103,
notes: []
}
]
body.notes before merging :
[
{
content: '<p>testing</p>',
date: Thu Apr 16 2015 10:14:44 GMT+0200 (Rom, sommertid),
writer: 55193679026666b00554d00e,
_id: 552f6f7435828478156f6103,
notes: []
},
{
content: '<p>bla bla</p>',
date: '2015-04-16T08:25:24.431Z',
writer: 55193679026666b00554d00e
}
]
notes after merging :
[
{
content: '<p>testing</p>',
date: Thu Apr 16 2015 10:14:44 GMT+0200 (Rom, sommertid),
writer: 55193679026666b00554d00e,
_id: 552f6f7435828478156f6103,
notes: []
},
{
content: '<p>testing</p>',
date: Thu Apr 16 2015 10:14:44 GMT+0200 (Rom, sommertid),
writer: 55193679026666b00554d00e,
_id: 552f6f7435828478156f6103,
notes: []
}
]