0
votes

Based on new version of firebase dependencies in flutter, there is new filters such like isNotEqualTo, arrayContains, arrayContainsAny, whereIn and so on.

I try to create streambuilder with some filters, I want to get documents that matches these conditions.

  1. The "uid" field value Does not equal current uid. (isNotEqualTo)
  2. The "school" field value isEqualTo current user school.(isEqualTo)
  3. The "random" field value isGreaterThanOrEqualTo random number that the app generated it (isGreaterThanOrEqualTo)

stream: fireStore.collection(USERS_COLLECTION).where(UID_FIELD, isNotEqualTo: me.uid).where(SCHOOL_FIELD, isEqualTo: me.school).where(RANDOM_FIELD, isGreaterThanOrEqualTo: random).limit(10).snapshots(),

Condition 1 (isNotEqualTo) does not work with me, but 2 and 3 it's working fine, when I add the filter 1 there is error showing to me.

All where filters with an inequality (<, <=, >, or >=) must be on the same field. But you have inequality filters on 'FieldPath([uid])' and 'FieldPath([random])'. 'package:cloud_firestore/src/query.dart': Failed assertion: line 486 pos 18: 'hasInequality == field'

1

1 Answers

0
votes

That is a Firestore-Limitation https://firebase.google.com/docs/firestore/query-data/queries

Note the following limitations for != queries:

Only documents where the given field exists can match the query. You can't combine not-in and != in a compound query. In a compound query, range (<, <=, >, >=) and != comparisons must all filter on the same field.

So you can either filter using != on the uid OR you can filter using >= on Random. You cannot do both in the same query.

I'd recommend filtering without the UID and let your repository filter out the UID later, once you've received the snapshots.