Reputation: 3
I need to store a list of strings in a field and I need to be able to easily access each string by its value, but there isn't a "set" or "1d map" option in firestore. As a hack, I used a map and just stored each of the strings as "value": value. But firestore's array's methods and functionality seems to behave like a set, and if so it would be perfect for storing this type of data. Are firestore array's implemented as sets or more as a traditional array?
Upvotes: 0
Views: 62
Reputation: 599071
Firestore arrays are just arrays, but come with some special operators that allow you to use them as sets too.
Specifically, you can perform unions on arrays, which add an item to the array if it is not in there yet.
You can also query on documents where an array contains a specific, or one of a number of values.
Note that in all these cases (unions and queries), you need to specify the entire array value and cannot specify only one property of them. In your case with simple string values that makes sense, but when you store objects in arrays this also applies: you must specify the entire object for the query to match it.
Upvotes: 1