문제

In MongoDB I've stored dates prior to B.C has String type. How can I stored in ISODate() type ?

I've tried this :

db.test.insert({"date" : new ISODate("-63-09-23") })

but I get an error :

uncaught exception: invalid ISO date

Thanks for your help !

도움이 되었습니까?

해결책

The MongoDB IsoDate() is just a wrapper around the normal javascript Date, which can take dates to 100 million days before 1970, so something like setFullYear() is probably what you need - like this: Can you create dates that are lower than 271800 BC? Like dinosaur time?

다른 팁

As Nik pointed out MongoDB dates are just javascript Dates. So you need to transform an ISODate back and forth to the underlying javascript Date. If you don't need to do queries based on the date you can also optionally store the date as a string instead.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top