title: mongoose - update many from an array of Ids
body: <p>im trying to update all keys ('indexOrder') in an array of objects in a document.
  The values for the update are recived as an array from the client:</p>
  <pre><code>[{_id:'1s284hd72hdd', indexOrder: 1}, {_id:'543543531', indexOrder: 2}, etc..]
  </code></pre>
  <p>im trying to match the _id of the array from the client with the _id of the objects in the document. When a match is found -&gt; it needs to update the 'indexOrder' in the document to its value from the array from the client.</p>
  <p>currently im doing it with looping on the client array, and updating for each iteration.</p>
  <pre><code>  async updateIndexOrder(orderList) {
      try {
        orderList.forEach(async ({_id, indexOrder}) =&gt; {
          await Model.findOneAndUpdate({_id}, {$set:{indexOrder}})
        })
        return true;
  
    } catch (err) {
      throw new Error(err);
    }
  }
  
  </code></pre>
  <p>How can I update in one call instead of so many server calls?
  something like:</p>
  <pre><code>  async updateIndexOrder(orderList) {
      const idList= orderList.map(x =&gt; x._id)
      try {
        await Model.updatMany(
      {_id: {$in:{idList}},
      {$set: {indexOrder: orderList[FIND INDEX OF THE ITERATING _id].indexOrder}}
      )
  
    } catch (err) {
      throw new Error(err);
    }
  }
  </code></pre>
  <p>Thank you.</p>