Basically, I want to subtract two fields from each sub-object in an array field of an input document and then update the document to include the calculated value.
For example,
{
"title" : "The Hobbit",
"rating_average" : "???",
"ratings" : [
{
"title" : "best book ever",
"start" : 5,
"finish" : 7
},
{
"title" : "good book",
"start" : 4,
"finish" : 8
}
]
}
I want to subtract finish-start for each object and then save that new calculated field into my existing documents.
So after updating my documents it should look like:
{
"title" : "The Hobbit",
"rating_average" : "???",
"ratings" : [
{
"title" : "best book ever",
"start" : 5,
"finish" : 7
“diff”:2
},
{
"title" : "good book",
"start" : 4,
"finish" : 8
“diff”:4
}
]
}
So, how can I do this?
Thanks in advance.