Must pouchdb _id property values be globally unique?

房东的猫 提交于 2019-12-24 09:18:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!