pouchdb _id属性值必须是全局唯一的吗? [英] Must pouchdb _id property values be globally unique?

查看:74
本文介绍了pouchdb _id属性值必须是全局唯一的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PouchDB手册建议使用 Date()。 toJSON()为每个文档生成一个新的ID。 然而,这导致_id值相同。。 PouchDB是否具有用于处理此问题的内置机制,还是应该使用类似 eventid 之类的东西?

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?

特别是 Date()。toJson()可能会在同一时刻生成id值:

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

如果文档已经具有<$ 2018-01-26T21:12:15.574Z 中的c $ c> _id ,并尝试使用相同的 _id 2018-01-26T21:12:15.574Z ,pouchdb会引发异常或以某种方式更改 _id 属性,使其成为唯一的ID?例如 2018-01-26T21:12:15.574Z_1

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会自动为新文档生成ID。我们通常喜欢将文档的独特属性(例如名称或位置)与date.toJSON结合使用,以使ID具有自我描述性。您只需查看_id即可知道文档的内容

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

这篇关于pouchdb _id属性值必须是全局唯一的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆