Domanda

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 !

È stato utile?

Soluzione

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?

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top