Can I somehow add custom field with static (not computed) value?
I want to prepare objects before send and I need to remove some fields with internal information and
Note that $literal was implemented in Mongo 2.6. So now you can simply write:
db.test.aggregate(
{$project: {_id: 0, data: 1, entity_id: {$literal: 54}}})
See $literal.
edit as of 2.6 the $literal
expression exists so you don't have to use the workaround now.
Original answer: I know this may sound really dumb, but you can use a "no-op" expression to "compute" what you need.
Example:
db.test.aggregate( { $project : {_id:0, data:1, entity_id: {$add: [54]} } } )
There was a proposed $literal
operator for exactly this use case but it hasn't been implemented yet, you can vote for it here.