Added: sum & sumMany
Before now sum
does the work of both single
and multiple
keys but this gets difficult when dealing with types and readability.
Old
// sum one key
await Model.sum("fiat") // number
// sum multiple keys
await Model.sum(["fiat", "crypto"]) // {fiat: 200, crypto: 2.456}
// sum multiple fields with nick names
await Model.sum({totalFiat: 'fiat', totalBitcoin: 'crypto'}) // {totalFiat: 200, totalBitcoin: 2.456}
New
Docs: https://xpresserjs.com/xpress-mongo/model.html#sum-async
// sum one key
await Model.sum("fiat") // number
// sum multiple keys
const sum = await Model.sumMany(["fiat", "crypto"]) // {fiat: 200, crypto: 2.456}
// sum multiple fields with nick names
const sum2 = await Model.sumMany({totalFiat: 'fiat', totalBitcoin: 'crypto'}) // {totalFiat: 200, totalBitcoin: 2.456}
With types support: sum
and sum2
will be typed to have defined keys.