firebase - What is the best practice for a multi-tenant app with Collection Group Queries in Firestore?
问题描述
What is the best practice for multi-tenant app collection group queries? For example query all invoices for a tenant's customers
/tenant/1/customer/2/invoices
If I create a collection group index called invoices, and I want to ensure that I can get all invoices for tenant 1, how do I do this easily?
I tried setting up some security rules to prevent from querying over the tenants but it still threw Access denied errors since it was still querying across tenants. What would the correct firestore rules look like
解决方案
Firebase 项目不太适合多租户应用。建议您为每个租户创建不同的项目。 这将为您在将来节省很多问题。
如果您绝对必须在单个项目上进行多租户,那么您当前的数据库结构不能很好地支持集合组查询。集合组查询总是查询给定名称的每个集合,没有例外。您不能使用安全规则来过滤结果,因为规则不是过滤器。过滤只能来自客户端,并由安全规则确认。使用您当前的结构,您需要将租户的 ID 存储在您打算使用集合组查询查询的每个文档中,并让客户端将其用作结果的过滤器。
推荐阅读
- wordpress - 以“cif-series”开头并列出带有链接的帖子标题的 Wordpress 标签
- python-3.x - 我的while循环不会重复问题
- git - git:涂抹仅在启用 textconv 时运行
- python - 将自定义 pyqtsignal 从一个主窗口发送到另一个主窗口
- apache-kafka - 处理 Kafka Producer 连接丢失
- python-3.x - 在 Python 中使用 Numpy.Where 和 Pandas.Shift 的 If 语句
- c++ - 类模板中文字运算符的友元声明
- java - 如何通过微调器使用共享首选项
- jquery - AJAX / Jquery 发布或获取
- c++ - Visual Studio 未链接源文件