Get cumulative values

Hi!

How can I get the accumulated value of one param? I mean I have a query that get documents from two collections. All documents have a parameter quantity and price. Some add quantity and others rest quantity. I have ordered them by date and I’d like to have a new parameter, say accumSoFar, that is the accumulated value of the quantity. Example:

I’m working with node.js. And although my version of mongodb is 4.0.1, which should support $setWindowFields when I try this approach it just fires an error like: unrecognized name $setWindowFields

const arr = [
    {
        sign: '+',
        quantity: 3
    },
    {
        sign: '+',
        quantity: 5
    },
    {
        sign: '2',
        quantity: 2
    }
]

An the end product should be

const arr = [
    {
        sign: '+',
        quantity: 3,
        accumSoFar: 3
    },
    {
        sign: '+',
        quantity: 5,
        accumSoFar: 8
    },
    {
        sign: '-',
        quantity: 2,
        accumSoFar: 6
    }
]```