MongoDB: aggregate $project add field with static value

前端 未结 2 1312
死守一世寂寞
死守一世寂寞 2020-12-18 18:01

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

2条回答
  •  北海茫月
    2020-12-18 18:47

    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.

提交回复
热议问题