'Get the difference between data in date range aggregation

I have data im getting using a date range to date and from date :

    {
      $match: {
        "Date_stock":
        {
          $gte: new Date(req.body.fromDate),
          $lt: new Date(req.body.toDate)


        }
      }
    },

I'm trying to get the difference between each doc's stock like doc 1 stock - doc 2 stock .

I'm using group to get the data:

      { $group: {
      "stock":{$toInt:"$stock"}
      }}

I dont have any related databases involved . each document has stock number .

how do i subtract the same value from group ?

is this possible to do ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source