Decrement value in mongodb

后端 未结 1 578
深忆病人
深忆病人 2021-01-22 15:13

I am creating a shopping application. Each user have wallet. Structure is like :

{ 
    \"userName\" : \"Gandalf the Grey\",
    \"wallet\" : 100,
    \"orderHi         


        
相关标签:
1条回答
  • 2021-01-22 15:31

    You can use $inc operator

    db.collection('users').updateOne(
      { 'userName': controller.userName },
      { '$inc': { 'wallet': -product.cost } }
    )
    
    0 讨论(0)
提交回复
热议问题