I have a collection with such documents stuct:
{
id: 1,
my_field: [
{
date: date1,
type: A,
value: 1
},
{
date: dateX,
type: X,
value: Z
},
...
]
What the problem i solve:
I have id, date, type and value. I have to find document by id(which is always present), then element in my_field
by date
and type
and increment value. If this element doesnt present in my_field
i have to insert it(struct to my_field
). And i look for the most efficient way
I will be very thankful for ideas!
Mongo 4.2
Also it will be great if someone helps with to write this on ruby-driver for mongo :)
Thanks!