|
SERVER-40381 implemented support for aggregation expressions to specify update for 4.2.
You can see some examples here.
This can be done by setting the array to its old value if the name already exists, or $concatArrays if it does not.
The more complex "upsert to array" that was mentioned:
db.c.update({}, [
|
{$set:{array:{$cond:{
|
if: {$in:[ "Scott" , "$array.name"]},
|
then:"$array" , // process array making appropriate change to correct element
|
else: {$concatArrays: [ "$array", [ {name: "Scott"}] ]}
|
}}}}
|
]);
|
|