'How to update or create an array if it doesnt exist in firestore realtime database

I'm working on a react application that stores some id's in an array based on some users. If the user doesn't have any id, the array will be empty. Is there any way I can dynamically create or update in firebase realtime database.

There is a collection named users And under users there are separate docs under each userId. So everytime a subscription is made I update the array named subscriptionStats under the collection. I would like to dynamically create or update this array.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source