Adding a normal function in a aggregation pipeline

Can I use a normal javascript function inside the aggregation pipeline. My query is not about $function operator. I am using cosmosdb for mongo API, which doesn’t support the $function. In one of the stack overflow thread I saw direct usage of function like below

let getStatus = (flag) => {
    return flag=='ok' ? 'ok' :'broken';
}
aggregate({
    $project: {
        '_id': 1,
        'status': getStatus($flag3)
    }
});

Ref: node.js - Call function inside mongodb's aggregate? - Stack Overflow

Is it possible ?

Why would you want to do that?

If your aggregation is really that simple you could simply evaluate $flag3 directly in your application.

If you need the value of status further in your aggregation the simplest thing to do is to use $cond with something like

{ "$cond" : [ { "$eq" : [ "$flag3" , "ok" ] , "ok" , "broken" } ] }

in your $project rather than getStatus(…).