I am developing an application in react-native + Cloud Firestore, which aims to generate random numbers/tickets for each user who fill out a form. These numbers will allow the user to participate in an electronic lottery and compete for the prizes of a promotion.
These numbers should be separated by series, for example:
Series 1 - numbers can range from 0 to 99,999 thousand.
Series 2 - numbers can range from 0 to 99,999 thousand.
Series N - numbers can range from 0 to 99,999 thousand.
The system requirements are:
- The series and numbers generated for each user must be maintained (numbers saved for the Client);
- Each promotion must also contain the generated numbers and series (Numbers generated in the Promotion, Total);
In a first structure in Cloud Firestore, we created a structure as follows:
Promotion - Series - Number
(random doc) - 01 - 00131 ...
(random doc) - 01 - 97879 ...
(random doc) - 09 - 99999
Promotion is a collection, the Series is a promotion sub-collection, and Number is a Series sub-collection.
However, in this way many queries have been made in the firestore API, for example, to obtain the available numbers to be generated within a series, so that a new number can be generated.
Another approach we have found is that the subcollection of numbers could be an array within the Series collection. This would reduce queries.
Will the 100,000 number array exceed the maximum 1mb document size? It could be used a structure with map, for example, to write beyond the number other properties as follows:
Promotion - Series - Numbers: Map?