title: MongoDB execution time of Aggregate Query
body: <p>I am trying to find execution time for an aggregation query.Query is like below:</p>
  
  <pre><code> db.table.aggregate([{$sort: {count:-1}}]);
  </code></pre>
  
  <p>it sorts the 100K documents by count desc.The command line did not show all the records so i did the following instead:</p>
  
  <pre><code> db.table.aggregate([{$sort: {count:-1}}]).toArray();
  </code></pre>
  
  <p>I have done db.setProfilingLevel(2);</p>
  
  <p>when I run first query and do :</p>
  
  <pre><code> db.system.profile.find((),{millis:1});
   I get millis : 18
  </code></pre>
  
  <p>when I run second query and find time from profile</p>
  
  <pre><code> I get millis:18 , millis:87 , millis: 81 ... millis:75, millis:35. I get 12 different execution times.
  </code></pre>
  
  <p>I wanted to know if i want to correctly measure the execution time of aggregation where I order the whole collection by count desc. What is the proper way. Is the query with .toArray() the correct query for measuring execution. Can you please help me on how I shall measure the execution time.</p>