title: How to fix MongoError: Cannot use a session that has ended
body: <p>I'm trying to read data from a MongoDB Atlas collection using Node.js. When I try to read the contents of my collection I get the error <code>MongoError: Cannot use a session that has ended</code>. Here is my code </p>
  
  <pre><code>client.connect(err =&gt; {
      const collection = client
          .db("sample_airbnb")
          .collection("listingsAndReviews");
  
      const test = collection.find({}).toArray((err, result) =&gt; {
          if (err) throw err;
      });
      client.close();
  });
  </code></pre>
  
  <p>I'm able to query for a specific document, but I'm not sure how to return all documents of a collection. I've searched for this error, I can't find much on it. Thanks</p>