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

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -