I am new at MongoDB and I want to increase the "rate2" of the "increase" array by 100%. It is located in my "CUSTOMER.ratings" document that has first name of "Jimmy".
The collection is like this:
db.collection.insert(
{
"CUSTOMER": {
"first name": "Jimmy",
"ratings": [{"increase": {"rate":99}, {"increase": {"rate2": 20.5}}]
}
}
);
I tried the following, but it created a new set insted putting a new address inside the array of location:
db.collection.update({"CUSTOMER.first name": "Jimmy"}, {$mul:{"ratings":{"increase":{ "rate2": 2 }}}});
I tried to put the "ratings" prior to the $mul put it doesn't work.
I need the right prototype of doing such thing.
The expected outcome is the following:
db.collection.insert(
{
"CUSTOMER": {
"first name": "Jimmy",
"ratings": [{{"increase": "rate": 99}},
{"increase": "rate": 41}}
]
}
}
);
To sum up, I want to increase rate2 by 100% .
To not be confusing, consider the following:
A
B[
C {rate}
C {rate2} ]
So how to multiply the value of "rate2"?
I tried {$mul: {"A":{"B":{"C":2 }}}};
Also, I tried {$mul: {"A.B.C": 2}};
Also, I tried {"A.B": {$mul: {"C": 2}}};
Also, I have used the $pull and $push prototype, but not sure why not working!!