title: MongoDB query returns null even though it is available in the collection after migrating from mlab to mongoDB atlas
body: <p>I am migrating a database from Mlab to MongoDB Atlas. We had to upgrade the npm version of mongodb to <code>3.4.1</code> as the MongoDB atlas database version is <code>4.2.5</code>.</p>
  <p>The connection function has been updated as said in this <a href="https://stackoverflow.com/questions/47662220/db-collection-is-not-a-function-when-using-mongoclient-v3-0/47974041#47974041">answer</a>. But after upgrading the npm version to <code>3.4.1</code> the findOne query returns a null value even-though the document is available in the collection. Here is the code section related of the findOne query,</p>
  <pre><code>  db.collection('organisations').findOne({ _id: database.ObjectID(orgState) })
      .then((activeOrganisation) =&gt; {
        console.log(activeOrganisation);
        data.activeOrganisation = activeOrganisation;
        callback(null, activeOrganisation);
      }, (error) =&gt; {
        callback(error, null);
      });
  </code></pre>
  <p>Because of this I was wondering whether there is a problem with the database connection so I tested it with running <code>db.serverConfig.isConnected()</code> , <code>db.databaseName</code> and <code>db.listCollections().toArray()</code>. The <code>isconnected</code> returned <code>true</code> and the returned database name is also correct. But <code>db.listCollections().toArray()</code> returned an empty array which means there are no collections in my database which cannot be.</p>
  <p>Then I tried a <code>findOneAndUpdate</code> query just to check what happens with that. Here is the relevant code for it,</p>
  <pre><code>db.collection('users').findOneAndUpdate(
          { emails: { $elemMatch: { email: &quot;rajitha1591@outlook.com&quot; } } },
          { $addToSet: { unsubscribedEmails: &quot;models&quot; } })
          .then((result) =&gt; {
            console.log(result);
      
              if (!result) {
                  console.error('Error: ', 'User not found')
              }
              console.log('Output: ', 'Sucessfully unsubscribed');
              callback(null,'Successful')
          }, (error) =&gt; {
              callback(error, null);
          });
  </code></pre>
  <p>The result contained,</p>
  <pre><code>{
    lastErrorObject: { n: 0, updatedExisting: false },
    value: null,
    ok: 1,
    '$clusterTime': {
      clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1586436331 },
      signature: { hash: [Binary], keyId: [Long] }
    },
    operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1586436331 }
  }
  </code></pre>
  <p>This clearly says that the document didn't got updated(<code>updatedExisting: false</code>). I checked the related document in MongoDB Atlas using the web browser as well and the document wasn't updated by adding the <code>&quot;models&quot;</code> value to the <code>unsubscribedEmails</code> array.</p>
  <p>In addition to that I tried a fresh install of <code>node_modules</code> by  deleting the <code>package-lock.json</code> as well.</p>
  <p>Since I migrated the database from mlab is it a possibility that  exceeding <a href="https://docs.mongodb.com/manual/reference/limits/#sharded-clusters" rel="nofollow noreferrer">limits  of MongoDB shared cluster</a>  to occur this issue.</p>
  <p>It would be nice to hear suggestions regarding this issue</p>