使用生成的 uuid v4 创建 firebase 文档如何重复证明?
我正在开发一个应用程序,它将向 firestore 数据库注入文档,这些文档将具有由 uuid v4 生成的 id 问题是,不同浏览器上的 2 个用户是否可以使用相同的 id 创建相同的文档?因为 uuid 功能是相同的?如果发生重复,它将覆盖某人的数据!如果 uuid 不是按时间戳生成 id。 否则,两个用户将有相同的参考,这也是非常糟糕的情况! npm uuid 可以用于此目的吗?
import { v4 as uuidv4 } from 'uuid';
const id = uuidv4();
I am working on an app the will inject docs in to firestore database those docs will have an id generated by uuid v4 the question is could 2 user every user on a different browser created same doc with the same id ? since the uuid function is the same ? if a duplicated could occur it will overwrite someone's data! in case if uuid is generation the ids not by timestamp.
other wise 2 users will have same reference which also really bad case ! could npm uuid be used for this purpose ?
import { v4 as uuidv4 } from 'uuid';
const id = uuidv4();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想在实际添加文档之前获取要添加到 Firestore 的文档的 ID,请查看 添加文档:
这是 SDK v9 或更高版本的 JavaScript 代码。其他语言的代码可以在上面的链接中找到。
If you want to get the ID of a document you're adding to Firestore before the document is actually added, have a look at this section of the Firebase documentation on adding a document:
This is the JavaScript code for v9 or later of the SDK. Code for other languages can be found at the link above.