简体   繁体   中英

Must pouchdb _id property values be globally unique?

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM