title: Node js throws MongoError: Cannot use a session that has ended while updating multiple documents in multiple collections
body: <p>I am trying to update multiple documents in multiple collections in a DB. While doing that Mongo throws an error after the first collection. And doesn't make changes on the after ones. </p>
  
  <p>Error </p>
  
  <blockquote>
    <p>Assertion failed: MongoError: Cannot use a session that has ended</p>
  </blockquote>
  
  <pre><code>const migration = async function migrate(client, dbName) {
      const engineDatabase = client.db(dbName);
      console.log(`connected to db ${engineDatabase.databaseName}`);
  
      const collections = await engineDatabase.collections();
      for (const collection of collections) {
          console.log(collection.collectionName);
          collection.updateMany({}, {$set: {"ownerIds": ["-1", "1"]}}, function (err, res) {
              console.assert(err == null, err);
  
              console.log(res.result.nModified + " document(s) updated");
              }
          ) 
      }
  };
  module.exports = migration;
  </code></pre>
  
  <p>Do I have to close the client after every update? Or do I have to wait for the next update? I couldn't get what's the point of this error.</p>