问题
The PouchDB Manual suggests using Date().toJSON()
to generate a new id for each document. However this an result in _id values that are identical.. Does PouchDB have a built in mechanism for dealing with this or should we be using something like eventid?
Specifically the Date().toJson()
could produce id values are at the same instant in time like this:
2018-01-26T21:12:15.574Z
2018-01-26T21:12:15.574Z
2018-01-26T21:12:15.575Z
If a document already has an _id
of 2018-01-26T21:12:15.574Z
and another attempt is made to create a new document with the same _id
value 2018-01-26T21:12:15.574Z
, will pouchdb throw an exception or somehow change the _id
property such that it becomes a unique id? For example 2018-01-26T21:12:15.574Z_1
.
回答1:
Pouchdb/Couchdb auto generates ids for new documents if that's what you are asking. we usually like to combine unique props of the doc like name or location with the date.toJSON to make ids self descriptive. you take one look at the _id and you know what the doc is about
来源:https://stackoverflow.com/questions/48430626/must-pouchdb-id-property-values-be-globally-unique