This is a sample aggregation stage that insert a field into every document.
Steps:
- Git clone the mongodb source code.
- Create a directory called 'modules' in
src/mongo/db/modules
. - Git clone this repo as
src/mongo/db/modules/inject
- Build MongoDB
- Now try the new aggregation stage:
db.foo.aggregate( { $inject : "funField" } );
This gist has been tested with:
- MongoDB master. Currently is at git version
3125749c23f8cf341768ecc37c86e64a2c30a356
orv3.3.1-229-g3125749
. - MongoDB branch v3.2.
- MongoDB tag r3.2.1.
See Blog: Extending the aggregation framework for more information.