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

Time:07-27

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()

CodePudding user response:

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)
  • Related