Hi, I would like to update some fields by MongoDB.
sample of schema:
{
id:1
name: 'John',
phone: {cell: 1234, work: 15345},
grades: [
{ id: 'C1', grade: 5, q:1},
{ id: 'C2', grade: 6, q:1},
{ id: 'C3', grade: 3, q:2}
]
}
Change Input (find id=1 and change the name and grade with id=C2 and change only phone cell)
input = {
id:1,
name='Samanta',
phone: { cell: 2346},
grades: { id:'C2', grade: 7}
}
Expected Result:
{
id:1
name: 'Samanta',
phone: {cell: 2346, work: 15345},
grades: [
{ id: 'C1', grade: 5, q:1},
{ id: 'C2', grade: 7, q:1},
{ id: 'C3', grade: 3, q:2}
]
}
Actually, I am looking to find a solution to merge the input and document by Ids (document and subdocument)
I appreciate any advice (it can be MongoDB or mongoose).