newb wandering around node / mongo on localhost os x 10.6.8 Not using middleware as I want to understand what's going first.
Imported multiple documents into mongo. Attempting to find by date but getting a mismatch. The date is correct in mongo and finding from the mongo shell but off by a day earlier in node.
mongo
db.dates.find({date: new Date('1957-07-05')})
output
{ "story" : "poster" : "admin", "date" : ISODate("1957-07-05T00:00:00Z"), "_id" : ObjectId("519d59eb4b35dd72180002bf") }
node
collection.find({date:new Date('1957-07-05')}).toArray(function(err, items) {
console.log(items);
});
console output
[ { poster: 'admin',
date: Thu Jul 04 1957 20:00:00 GMT-0400 (EDT),
_id: 519d59eb4b35dd72180002bf } ]
SOLUTION(?)
Anyone getting here it seems like .toISOString() from above console.log(items[0].date); var wdf = new Date(items[0].date).toISOString(); console.log(wdf);
Node uses your current timezone (in this case EDT (GMT-0400)) when you construct a date without an explicit timezone, while mongo just uses UTC.