The PouchDB Manual suggests using Date().toJSON() to generate a new id for each document. Do all javascript runtimes guarantee that Date().toJSON() will always be unique?
The dates only have microsecond precision, so there's no guarantee they will be unique.
The snippet below will give you a number of duplicates in all but the slowest runtime environments:
for (let i = 0; i < 10; i++) {
console.log(new Date().toJSON())
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With