问题
In RDBMS, suppose we have 4 columns , say col1, col2, col3, col4
If we want col4
value to be col1 + col2 - col3
,
we can write an update statement as follows:
Update Table set col4=col1+col2-col3
Is doing multiple operations possibe using Mongo shell aggregation?
I tried to get the sum of two fields using aggregation with following query.
db.students.aggregate([
{
$project: { examTotal: { $add: [ "$final", "$midterm" ] } }
},
{ $out: "students" }
])
But with this query its replacing the fields in the same collection. How could this be achieved?
col4=col1+col2-col3
and update the col4
value in same collection. Can this be possible within a single step?
来源:https://stackoverflow.com/questions/35240667/how-to-do-multiple-aggregation-operations-in-mongoquery-and-update-the-field-in