Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 491 Bytes

add-fields.md

File metadata and controls

30 lines (24 loc) · 491 Bytes

Demo for AddFields

Example of code

import {AggregateBuilder, toString} from 'mongodb-aggregate-builder';

const aggBuilder = new AggregateBuilder();
aggBuilder.addFields({
    ...toString('age', 'stringAge'),
    value: 123
});
console.log(JSON.stringify(aggBuilder.build(), null, 2));

Result

[
    {
        "$addFields": {
            "stringAge": {
                "$toString": "$age"
            },
            "value": 123
        }
    }
]