title: Mongo Export dump of collections inserted after specific day and time
body: <p>I am trying to dump all the entries made in a MongoDB since midnight each day. I created a unix script that uses 'mongoexport' utlity. It is returning zero records. Here are the commands.</p>
  
  <pre><code># Generate a variable that stores today's date and 00:00 hours in epoch format
  toDay=$(date +%Y-%m-%d)
  todayMidnightEpoch=$(date -d "${toDay} 00:00:00" "+%s")
  
  # Now plug this epoch variable into mongoexport command
  mongoexport \
  --host &lt;hostname&gt; \
  --username &lt;user ID&gt; \
  --password &lt;password&gt; \
  --db &lt;db name&gt; \
  --limit 100000 \
  --collection &lt;collection name&gt; \
  --out filename-$(date +%Y%m%d).json \
  --query '{created_at:{"$gte": "new Date(${todayMidnightEpoch})"}}'
  </code></pre>
  
  <ol>
  <li>I am running this script on CentOS+MongoDB server. </li>
  <li>I tested the mongoexport command with no query option and I get the output of all documents almost immediately.</li>
  </ol>
  
  <p>I get zero records after running for more than 10-20 minutes. 
  When I run the same 'query' with the variable replaced by actual epoch value on Mongo Shell I get the right output instantaneously.</p>
  
  <pre><code>db.&lt;collection name&gt;.find('{"created_at":{"$gte":new Date(140013360000000)}}')
  </code></pre>
  
  <p>Even when I hard coded the epoch value in the mongoexport command, I got one record.</p>
  
  <pre><code>mongoexport --host &lt;hostname&gt; --username &lt;username&gt; --password &lt;password&gt; --db &lt;db name&gt; --limit 10 --collection &lt;coll name&gt; --out test-$(date +%Y%m%d).json --query '{created_at:{$gte:new Date(1431561600000)}}'
  </code></pre>
  
  <p>Questions:</p>
  
  <ul>
  <li>Why does it return the records (or documents) when a query is run with hard coded epoch value in mongo shell but not when it is passed through a unix variable in mongoexport utility?</li>
  <li>Is there a way to specify today's date and time as 00:00:00 in the query option without having to convert it into epoch format?</li>
  </ul>