Firestore clients and invoices, amended requiremen

2019-07-17 02:23发布

This question is a follow up question to the one posted here:

Firestore: Clients and invoices, how to model it

I am trying to understand the thought process behind modelling evolving requirements in Firebase/Firestore.

Assuming the accepted answer was used for the model, then 2 months you get a new requirement after the app has been released. Now the requirement says: We need to get the invoice detail (not only id but the full details) for user whose last name is xyz.

How can model this assuming the database/app has been live for 2 months (so there is data in there already). The last name is already an attribute of the user details.

Thank you

1条回答
再贱就再见
2楼-- · 2019-07-17 03:10

According to the requirements that we see in this post, which I understand are mandatory in your project:

Show invoices that a client has

and

Update all invoices in the system to false

The most appropriate schema that can I recommend you, is the one in which you should add a new property called userId, beneath each invoice object.

So please consider using this tehnique, which is actually called a the reverse lookup. It will help you query your database more easily and will also help you solve both problems.

查看更多
登录 后发表回答