title: Best way to count documents in mongoDB
body: <p>we have a collection with big amount of documents, lets say around 100k. We now want to count the number of documents which has the key <code>x</code> set.</p>
  
  <p>If I try it with <code>Collection.countDocuments({ x: { $exists: true }})</code> I get the result, but it creates instantly a warning in the console: <strong>Query Targeting: Scanned Objects / Returned has gone above 1000</strong>.</p>
  
  <p>So, is there a better way to count the documents? There is a <code>Index</code> on the field, is it possible to get the length of the index?</p>
  
  <p>Thanks</p>