0

I'm having a weird issue with MongoDB in Windows 10. I've migrated a database that's working perfectly fine in MacOS and Linux to a Windows 10 machine.

Same mongodb version : 3.4.7

The issue seems to be related to one that other people experienced but it's not exactly the same (question question)

I get an error saying "gmtime failed - your system doesn't support dates before 1970" when I call a view that uses $dateToString in the projection.

And I also get only 101 records if I call the same view via Robo 3T.

But the difference in my case is that I don't have dates before 1970 in this particular collection.

So I ran this code on Robo 3T to try something, and I can't understand the result:

db.getCollection('vehicles').find({}).forEach(function(vehicle){
   var date = new Date(vehicle.dates.entry);
   print(date);
   print(date.getYear());   
})

This is the result for one record:

Fri Oct 02 2015 00:00:00 GMT+0100 (GMT Standard Time)
115

So the date seems to be constructed properly but the getYear() returns 115 instead of 2015.

The same code on MacOS or Linux works as expected.

Any ideas? Thanks

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Ricardo Gomes
  • 1,268
  • 2
  • 15
  • 35
  • That's a JavaScript thing. You mean `date.getFullYear()` – Neil Lunn Aug 31 '17 at 10:43
  • Hi @NeilLunn that might be the case but even if it is it's a mongo thing. The code I wrote was just a test to try this out, because I don't have dates prior to 1970 in this collection. I did try the getFullYear and it works. but I still have the same problem. I'll edit the question to remove that assumption. – Ricardo Gomes Aug 31 '17 at 11:05
  • Edit the question why? This is how the code for a JavaScript `Date` works. There is no other answer. You simply use `.getFullYear()` and not `.getYear()`. It's not that hard to work out. Your "edit" is a **different question** So I'm rolling it back to what you originally asked. If you have a new question the [Ask a new Question](https://stackoverflow.com/questions/ask) Instead. – Neil Lunn Aug 31 '17 at 11:08
  • See https://jira.mongodb.org/browse/SERVER-12816 as well – Neil Lunn Aug 31 '17 at 11:19

0 Answers0