android - 无需扫描整个集合即可共享 Firestore 文档

标签 android firebase nosql google-cloud-firestore

我正在学习 Firestore 的基础知识,并尝试构建一个允许用户 1 与用户 2/3/4 等共享文档的应用。

出于计费目的,导致文档读取的每个查询都计入成本。因此,我不想遵循将 user2/3/4 等电子邮件添加到“sharedWith”变量以键入:数组或映射类型结构的方法,因为我相信每个用户都必须扫描整个集合并选择他们的电子邮件出现的文档。

是否有任何其他方法可以让 user1 以编程方式授予对一个特定文档的 user2/3/4 的访问权限?

最佳答案

For billing purposes, every query which results in a document read counts towards the cost.

根据关于 Cloud Firestore billing 的官方文档,这是正确的:

There is a minimum charge of one document read for each query that you perform, even if the query returns no results.

因此,即使您的查询未返回任何结果,您也需要为阅读一份文档付费。

I believe every user will then have to scan the entire collection and pick the documents where there email appears.

这也是对的。因此,让我们假设您要查找的电子邮件地址存在于一个包含 10k 文档集合的文档中。因此,如果您仅针对该特定文档查询数据库,您将被收取仅读取一个文档的费用,而不是那些 10k 的费用。因此,您需要根据取回的元素数量而不是您要求的元素数量来收费。当您从 Firebase 服务器获取数据时,这可用于第一个请求。如果同时没有任何变化,第二次从缓存中获取数据,因为 Firestore 有 offline persistence默认启用。这意味着您无需为任何其他文档阅读付费。

Is there any other approach to this where user1 can programatically give access to user2/3/4 of one specific document?

不将数据写入数据库,就没有。因此,您应该将 ID 或电子邮件地址添加到所需的文档中,并根据它执行查询。

关于android - 无需扫描整个集合即可共享 Firestore 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54943532/

相关文章:

android - 构建旧版 Android AOSP

java - 如何在 Firebase 中进行类似于 SQL 查询的查询?

javascript - Firebase:创建命名子引用

c - 哪个 NoSQL 数据库与 C 一起使用?

android - onActivityResult 在 onDestroy 之前被调用

android - 使用 setUseNativeTextInput(false) 时,Android 上的 TextField 中的文本乱码;

android - CoordinatorLayout 使 View 未定位

firebase - 使用 firebase resize images extension 动态调整图像大小

python - 正在使用 Python 为 Cassandra Dumb 进行 MapReduce?

database - 应该使用什么数据库/技术来计算时间范围内的唯一身份访问者