title: mongodb count vs find with count
body: <p>I am performing a count of documents in a mongo (versions 2.4 and 3.2) collection.  The collection is very big, 3821085 documents.  I need to count all documents with a reference <code>_id</code>.  I have tried two different queries:</p>
  
  <p><code>db.SampleCollection.find({"field._id" : ObjectId("UUID")}).count()</code>
  <code>db.SampleCollection.count({"field._id" : ObjectId("UUID")})</code></p>
  
  <p>This query takes a very long time.  So much time that I have not let it complete, more than 5 minutes and I get scared and kill it.</p>
  
  <p>For this collection <code>field._id</code> is not an index.  I do not have relevant info to use an index with this query.</p>
  
  <p>Is there a better approach to count document in mongo.</p>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>I understand that I need an index on the field <code>field._id</code>.  If I did have an index for the field which approach would perform better on a large collection <code>db.SampleCollection.find(...).count()</code> or <code>db.SampleCollection.count(...)</code>?  Or is there no difference between the two?</p>