且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Firebase存储数据***实践

更新时间:2023-11-19 15:41:40

uid a唯一的id因此在/ users节点的情况下使用它们的uid作为父节点名称是很好的。

The uid is a unique id so it's great to use their uid for parent node names in cases like a /users node.

此外,如果每个用户都有自己的设置,那么它很酷包括那些进入/ users / uid / node的那些。

Also, if each user has their own settings, then it's cool to include those into the /users/uid/ node.

'更平坦更好'是座右铭但有时候扁平化可能实际上使事情过于复杂。在这种情况下,用户登录并读取其设置。完成。您不会查询它或进行任何类型的交叉引用查找,因此请将其与其他用户数据保持一致。

'Flatter is better' is the motto but there are times when flattening may actually overcomplicate things. In this case, a user logs in and their settings are read. Done. You won't be query-ing it or doing any kind of cross reference lookups so just keep it with the other user data.

一般情况下,您的方法是正确的:

In general your are on the right track:

使用自动创建的ID是一种很好的做法 - 这允许您取消节点名称与其包含的数据的关联。

Using auto created id's is good practice - this allows you to disassociate node names from the data it contains.

像电子邮件地址和人名这样的东西,实际上任何可能改变的东西都不是***的节点名称,因为它们可能会在你的结构中的其他200个地方被引用,如果电子邮件地址发生变化,例如,你将不得不寻找200个地方并进行更新。 (电子邮件地址也有特殊字符,因此您必须按摩它们才能使它们正常工作。)

Things like email addresses and people's names, and really anything that could change are not the best node names, as they may be referenced in 200 other places in your structure and if the email address changes, for example, you'll have to seek out 200 places and perform updates. (email addresses have special characters as well so you have to massage them to make them work anyway.)

使用自动生成的节点名称,您可以更改一次。

With a auto-generated node name, you change it once.