How can i filter list based on role.
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)