I have a document in which one of the fields is an array of objects containing multiple fields.
{
"_id" : "1",
"data" : [
{
"time" : 500,
"offset" : -20,
"sample" : 10
},
{
"time" : 700,
"offset" : -20,
"sample" : 30
}
]
}
I want to be able to update the array with new entries and also overwrite update the value of sample if an entry with a specific "time" and "offset" already exist.
For example if I pass in an array with values
[
{
"time" : 500,
"offset" : -20,
"sample" : 20
},
{
"time" : 600,
"offset" : -20,
"sample" : 10
}
]
The expected output would be
{
"_id" : "1",
"data" : [
{
"time" : 500,
"offset" : -20,
"sample" : 20
},
{
"time" : 600,
"offset" : -20,
"sample" : 10
},
{
"time" : 700,
"offset" : -20,
"sample" : 30
}
]
}
Is there a way to do this in a single statement?