Firebase Firestore“参考"数据类型有什么用处? [英] What is Firebase Firestore 'Reference' data type good for?

查看:88
本文介绍了Firebase Firestore“参考"数据类型有什么用处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在探索新的Firebase Firestore,它包含一个名为

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.

  • 像外键吗?
  • 它可以用来指向其他地方的集合吗?
  • 如果reference是实际参考,我可以将其用于查询吗?例如,我可以有一个直接指向用户的引用,而不是将userId存储在文本字段中吗?我可以使用此用户参考进行查询吗?
  • 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?

推荐答案

引用非常类似于外键.

当前发布的SDK无法存储对其他项目的引用.在项目中,引用可以指向任何其他集合中的任何其他文档.

The currently released SDKs cannot store references to other projects. Within a project, references can point to any other document in any other collection.

您可以像其他任何值一样在查询中使用引用:进行过滤,排序和分页(startAt/startAfter).

You can use references in queries like any other value: for filtering, ordering, and for paging (startAt/startAfter).

与SQL数据库中的外键不同,引用对于在单个查询中执行联接没有用.您可以将它们用于相关的查找(看起来像join),但是要小心,因为每个跃点都会导致到服务器的另一次往返.

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.

这篇关于Firebase Firestore“参考"数据类型有什么用处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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