Ravin Laheri
Ravin Laheri

Reputation: 822

How to filter Firebase data of Map<String, dynamic>

How can i filter list based on role. enter image description here

Currently I am using below stream for showing all data but I want to show data based on role of user.

stream: firebaseFirestore.collection('messages').where('users', arrayContains: userId).orderBy('timestamp', descending: true).snapshots()

Upvotes: 2

Views: 262

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598951

While Firestore supports an array-contains clause in its queries, that condition only matches if you specify the exact, complete array item. There's no operator to filter on a partial array item.

The common workaround is to add an additional array field with just the UIDs (e.g. uids) to each document and then filter on that with:

firebaseFirestore.collection('messages').where('uids', arrayContains: userId)

Upvotes: 1

Related Questions