Using arrays
Arrays in Firestore have some limitations that you should know to design your database schema efficiently:
- Arrays can’t contain array items, but you can put an array into an object item.
- No write helpers (e.g.,
$.serverDate()
,$.increment()
, etc.) are available for array items and nested objects. - You can’t use field paths to update array items. Doing so will replace the whole array and turn it into an object.
Given those limitations, it’s recommended to use arrays only for primitive values and objects for more complex data.
For example, a good example of using arrays would be a list of tags:
On the other hand, if you want to store more complex data, it’s better to use an object:
→ Learn more about how Typesaurus helps to make arrays type-safe