title: Mongoose aggregate match and addfield with provided list index
body: <p>I need to update the document's field order based on the index of the array I passed in. But when I call this API, the end result is [], and no expected changes in the database. Need your pieces of advice</p>
  
  <p>the arrayI passed in is:</p>
  
  <blockquote>
    <p>["5c1b9f2b66922a77ec7116a1", "5c1b9d4a66922b77ec81169f"]</p>
  </blockquote>
  
  <pre><code>exports.update_item_order = (req, res, next) =&gt; {
        const idList = req.body.idList;
        if (!idList) {
          res.status(400).json({
            message: "Missing request paramaters"
          });
        }
        vouchers.aggregate([{
          "$match": {
            "_id": {
              "$in": idList
            }
          }
        }, {
          "$addFields": {
            "order": {
              "$indexOfArray": [idList, "$_id"]
            }
          }
        }, {
          "$sort": {
            "order": 1
          }
        }]).exec((err, result) =&gt; {
          if (err) {
            return res.status(500).json();
          }
          return res.status(200).json({
            message: 'Status update successfully',
            result
          })
        })
      };
  </code></pre>
  
  <p>Sample collection I am retrieving from</p>
  
  <p><a href="https://i.stack.imgur.com/Wg4UM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wg4UM.png" alt="enter image description here"></a></p>