SuuSoJeat
SuuSoJeat

Reputation: 1136

How to put a set data type into Firestore?

I have a data class of A with a set of strings as the property. How do I put it into the Firestore?

data class A( val str: set<String> = emptySet() )

Upvotes: 0

Views: 43

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599131

A mathematical set is best mapped to an array in Cloud Firestore, which you then manipulate with the array-union and array-remove operators, and query using array-contains. These operators ensure that each value can occur only once in the array, which is required to make it mimic a set.

See:

Upvotes: 1

Related Questions