简体   繁体   English

pouchdb _id属性值必须是全局唯一的吗?

[英]Must pouchdb _id property values be globally unique?

The PouchDB Manual suggests using Date().toJSON() to generate a new id for each document. PouchDB手册建议使用Date().toJSON()为每个文档生成一个新的ID。 However this an result in _id values that are identical. 但是,这导致_id值相同。 . Does PouchDB have a built in mechanism for dealing with this or should we be using something like eventid ? PouchDB是否具有用于处理此问题的内置机制,还是应该使用诸如eventid之类的东西?

Specifically the Date().toJson() could produce id values are at the same instant in time like this: 具体来说, Date().toJson()可能会在同一时间生成id值,如下所示:

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? 如果文档已经具有_id2018-01-26T21:12:15.574Z并再次尝试创建具有相同_id2018-01-26T21:12:15.574Z的新文档, 2018-01-26T21:12:15.574Z将引发异常或以某种方式更改_id属性,使其成为唯一的ID? For example 2018-01-26T21:12:15.574Z_1 . 例如2018-01-26T21:12:15.574Z_1

Pouchdb/Couchdb auto generates ids for new documents if that's what you are asking. 如果您要这样,Pouchdb / Couchdb会自动为新文档生成ID。 we usually like to combine unique props of the doc like name or location with the date.toJSON to make ids self descriptive. 我们通常喜欢将文档的独特属性(例如名称或位置)与date.toJSON结合使用,以使ID具有自我描述性。 you take one look at the _id and you know what the doc is about 您只需看一下_id即可知道文档的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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