javascript - mongodb: how to multiply a field by a constant in an if else branket -
i have runningpnl field , description field date field.
want do:
if description "breakup" multipliedpnl=2*runningpnl
otherwise multipliedpnl=runningpnl
code is:
db.getcollection('user0').aggregate( [ { $project: { thedate: 1, realpnl: { $cond: { if: { $gte: [ "$description", "breakup" ] }, then: {$multiply:[$runningpnl,2]}, else: $runningpnl} } } } ] )
theres reference error : runningpnl not defined. whats wrong code? thx lot in advance help!
can try $mul? mongodb version?
reference: https://docs.mongodb.com/manual/reference/operator/update/mul/
an example documentation this
db.products.update( { _id: 1 }, { $mul: { price: 1.25 } } )
Comments
Post a Comment