1

I have a node app running on a Comfile Pi, which is a RPi Compute Module 3 mounted in the back of a touch screen interface. I'm gathering and storing data using MongoDB, which is running in the background as a service. On each document that I insert, I call the new Date(<"YYYY-mm-ddThh:MM:ss">) method to get the current date down to the second.

My system clock is correctly updated, but the Date method is returning the Unix Epoch (or very close to it) every time I store a new document.

Now, I've also used the library moment to store dates, but Mongo didn't seem to sort those correctly. Moment would correctly capture the updated time and date.

Is this an issue with Mongo itself? My clock takes several seconds to update every time on boot. Could Mongo be starting before this happens and starting with the wrong time info? Could it simply be an issue with the Pi itself? I'm fairly lost.

Further info: Normal ways of updating this Pi's clock didn't work for me. The only way I was able to make it function was the following console command:

Sudo timedatectl set-ntp True
0

I'm a moron! This is very easily fixed. I removed the <"YYYY-mm-ddThh:MM:ss"> from new Date() and it started to capture it perfectly. The <"YYYY-mm-ddThh:MM:ss"> was taken directly from this Mongo doc, though, so I'm not sure why that broke it.

So, to summarize, if you simply call new Date();, everything works as intended.

If you call new Date(<"YYYY-mm-ddThh:MM:ss">); Mongo will store the date as the Unix Epoch. This MAY have to do with the fact that I have to use an older version of Mongo (2.2) on the Pi and that version doesn't support the date format I was using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.