The variables in a $project
step are always the fields of the input document of that step. You can not yet access any values computed in the same step. But you can access any computed values in a following $project step. So you can break your computation into two $project-steps like this:
db.apps.aggregate(
[
{ $project : {
a: { $multiply : [2, 2] }
}
},
{ $project : {
a: 1,
b: { $divide: [5, "$a"] }
}
}
]
);