So I am trying to figure out the best structure for my use case.
Currently it looks like this:
salesItems | userId | salesItem1 |
| salesItem2 | and so on.
So the items are stored in a document named with the respective userid.
The problem with this is, that I am expecting this document to get bigger than 1MB.
So I thought maybe I need to setup collection group queries.
Therefore I set up a structure like this:
salesItems | userId | StoreA | documentId | startDate:
| endDate:
| salesItems:
| StoreB | documentId | startDate:
Where items get stored as chunks in a document, which get start- and enddate as fields to make it possible to query these chunks by date.
So a document would look like this:
startDate: 01/01/2021
endDate: 12/31/2021
salesItems:[items]
My goal is to query all documents across all stores for a user.
So my questions are:
- Do you think there is a better solution?
- If you also think I should go with collection group queries, what would be the correct security rule?
After watching fireships tutorial on collection group queries, it seems like there are special security rules needed for collection group queries.
Currently I am writing :
match /salesItems/{userId}/{documents=**} {
allow read, write: if true; //No restriction for testing purposes.
}
but that doesn't work.
Here is a screenshot of the current structure.
NOTE I need to store items in the 2 box. I plan to remove the 1 row, but thats not part of the question.