Let's assume this structure
class A
{
string Id;
int value
...
}
and
class B
{
int sum;
List<A> L;
some stuff
}
I have a Mongo table with objects B
What I need to do is the following, in pseudo code:
if (any A item of B has Id == XXX)
{
if (A.value > X)
{
B.Sum += A.Value;
A.Value = 0;
}
}
in one (atomic) operation.
The B.sum += A.Value and the A.Value = 0 need to be atomic.
I have absolutely no clue on how to implement that.
Has anyone done something similar with MongoDB before?