可以在Firestore中重用uuid吗? [英] Can a uuid be reused in Firestore?

查看:55
本文介绍了可以在Firestore中重用uuid吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

uuid是否可以在Firestore中重用并用于引用位于不同集合下的相关数据?

在一个测验应用中,例如,在数据库中,有一个 questions 集合,其文档是各个 questions .我将问题实例持久化到问题集合中,并获取其键 x .

如果使用同一键 x 将相同数据库中的 answers 集合中的问题的答案持久化怎么办?这可能吗?会导致下游并发症吗?

预期的用例是,如果将密钥x应用于问题集合,则得到问题;如果将相同的密钥x应用于答案集合,则得到问题的答案.

解决方案

不知道Firestore生成的ID是否确实符合UUID规范,但是它们仍然是ID.

在编写此答案时,可以在相同的Firestore生成的ID下,将不同的对象添加到属于同一数据库的不同集合中(尽管也可以使用用户生成的ID.);

使得相同的键(如果针对不同的集合进行赎回)会相应地击中不同的对象.

不知道这是否会使下游的架构复杂化.

Can a uuid be reused in Firestore and used to refer to related pieces of data, living under different collections?

In a quizzing app, let's say, in the db, there's a questions collection, whose documents are individual questions. I persist a question instance to the questions collection, and get its key x.

What if this same key x, is used to persist the answer to this question, in an answers collection in the same db? Is this possible? Could it lead to complications downstream?

The intended use case was, if the key x is applied to questions collection, we get the question, and if the same key x applied to answers collection, we get that question's answer.

解决方案

Don't know if the ids generated by Firestore actually conform to the UUID specification, they are ids nevertheless.

At the time of writing this answer, it is possible to add different objects under the same Firestore generated id, in different collections belonging to the same database (though it should be possible with user generated ids as well.);

such that the same key, if redeemed against different collections, hit different objects accordingly.

Don't know if this could complicate things architecturally downstream.

这篇关于可以在Firestore中重用uuid吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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