Articles → MONGODB → $Subtract Operator In The Aggregate Framework Of Mongodb

$Subtract Operator In The Aggregate Framework Of Mongodb






Purpose





Example




Picture showing the sample document collection in mongodb




db.sales.aggregate([
  {
    $project: {
      _id: 1,
      date: 1,
      amount: 1,
      discount: 1,
      effectiveAmount: { $subtract: [ "$amount", "$discount" ] }
    }
  }
])



Output


Picture showing the output of $subtract operator in mongodb





Posted By  -  Karan Gupta
 
Posted On  -  Friday, May 10, 2024

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250