什么是firestore引用数据类型适合? [英] What is firestore Reference data type good for?
问题描述
我只是在探索新的Firebase Firestore,它包含一个名为 参考
。我不清楚这是什么。
- 是否像外键?
-
- 如果
引用$ c $>是否可以用来指向位于其他位置的集合? c>是一个实际的参考,我可以用它来查询?例如,我可以有一个直接指向用户的引用,而不是将userId存储在文本字段中?我可以使用这个用户参考进行查询吗?
解决方案引用非常像外键。
当前发行的SDK不能存储对其他项目的引用。在一个项目中,引用可以指向任何其他集合中的任何其他文档。
您可以像查询其他任何值一样在查询中使用引用:用于过滤,排序和分页startAt / startAfter)。
与SQL数据库中的外键不同,引用对于在单个查询中执行连接是无用的。您可以使用它们进行依赖性查找(看起来像加入),但要小心,因为每一跳都会导致服务器再次往返。
I'm just exploring the new Firebase Firestore and it contains a data type called
reference
. It is not clear to me what this does.- Is it like foreign key?
- Can it be used to point to a collection that is located somewhere else?
- If
reference
is an actual reference, can I use it for queries? For example can I have a reference that points directly to the user, instead of storing the userId in a text field? And can I use this user reference for querying?
解决方案References are very much like foreign keys.
The currently released SDKs cannot store references to other projects. Within a project references can point to any other document in any other collection.
You can use references in queries like any other value: for filtering, ordering, and for paging (startAt/startAfter).
Unlike foreign keys in a SQL database, references are not useful for performing joins in a single query. You can use them for dependent lookups (which seem join like), but be careful because each hop will result in another round trip to the server.
这篇关于什么是firestore引用数据类型适合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!