Issue with Mongoose Timestamp and epoch conversion to Date()
<p>I have a Mongoose schema with the <code>timestamp</code> option set as true.</p>

<pre><code>schema = new mongoose.Schema({
    ...
},
{ timestamps: true });
</code></pre>

<p>Now I have an Android application that gets the timestamp using <code>System.currentTimeMillis()</code> which works all well and good and gives me number of milliseconds since UNIX epoch time.</p>

<p>I send this data across to my Node.js / Express server which takes the time and returns only documents created after that particular date.</p>

<pre><code>// get all docs
router.get('/api/seekers', function(req, res) {
    Seeker.find({createdAt:{ $gt: new Date(req.query.timestamp) }}, function(err, seekers) {
        if(err)
            res.send(err);
        else 
            res.json(seekers);
    });
});
</code></pre>

<p>So I send <code>https://api_url.com/api/seekers?timestamp=1479431351762</code> as a request to the server.</p>

<p>Now a couple of things happen:</p>

<ol>
<li><p>I send the value in milliseconds and get this error</p>

<p><code>{"message":"Cast to date failed for value \"Invalid Date\" at path \"updatedAt\"","name":"CastError","kind":"date","value":null,"path":"updatedAt"}</code></p>

<p>After a little bit of investigation, it turns out you need to pass seconds to <code>Date()</code>. So,</p></li>
<li><p>I divide the value by 1000 to get seconds (<code>req.query.timestamp/1000</code>). Now I wasn't getting an error, but the query constraint was not working. I'm getting all values since the beginning of time.</p></li>
<li><p>I moved over to the Mongo shell to check whether the issue persists, to which it turns out it <em>doesn't</em> since I can pass the millisecond value to Mongo's Date:</p>

<p><code>&gt; new Date(1479431351762)
ISODate("2016-11-18T01:09:11.762Z")</code></p>

<p>But if I tried passing the second value to <code>Date()</code>, it turns out it <em>actually was</em> sending me to the beginning of time:</p>

<p><code>&gt; new Date(1479431351)
 ISODate("1970-01-18T02:57:11.351Z")</code></p></li>
</ol>

<p>I'm unable to figure this out, what can I do so server request and mongoose correctly processes the timestamp and queries my db?</p>