Sna*_*ake 1 java android firebase google-cloud-firestore
我具有以下架构,但不确定如何在Firestore中对其进行建模。
我将有客户和发票。客户“有”发票。我需要能够执行以下两个查询:
对此建模的正确方法是什么?通过收集具有发票子集的客户来满足第一个查询。但是第二张帐单是否包含所有帐单,是令人满意的?
任何有经验的帮助表示赞赏
谢谢
I have another recommendation which involves you to create two top level collections like this:
Firestore-root
|
--- users (collection)
| |
| --- userId (documents)
| |
| --- //user details
|
--- invoices (collection)
|
--- invoiceId (documents)
|
--- yourBooleanProperty: true
|
--- userId: true
Run Code Online (Sandbox Code Playgroud)
As you can see, the simplest way to achieve this, is to have a single collection named invoices that can hold as documents all the invoices in your database. Because a single invoice can belong only to a single user, you can have the userId as a property. To get all the invoices that correspond to a specific user, I recommend you to use the following query:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
Query query = rootRef.collection("invoices").whereEqualTo(userId, true);
Run Code Online (Sandbox Code Playgroud)
And if you want to change the boolean property of all invoices from true to false at once, simply use the following query:
Query query = rootRef.collection("invoices").whereEqualTo(yourBooleanProperty, true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
286 次 |
| 最近记录: |