Home > database >  Flutter APP crashes when opening page with query
Flutter APP crashes when opening page with query

Time:11-27

Hello everyone while trying to open a page with a query the app starts to terminated again and again and again. I don't get a link to create index or anything like that its just terminating on iOS and on android im getting the error below .

This is the code

idofotheruser = await FirebaseFirestore.instance
            .collection('meinprofilsettings')
            .doc(user)
            .collection('BlockedUser')
            .limit(10)
            .get();

        idofotheruser.docs.forEach((element) {
          listOfIds.add(element.id);
        });
        if (idofotheruser.docs.length > 0) {
          print("test123");
          print(widget.hashtag);
          try {
            querySnapshots = await FirebaseFirestore.instance
                .collection('videos')
                .where('uid', whereNotIn: listOfIds)
                .where('Hashtagsforallvideos', arrayContains: widget.hashtag)
                .orderBy("uid")
                .limit(13)
                .get();
An error occurred while parsing query arguments, this is most likely an error with this SDK.
E/FLTFirestoreMsgCodec(16249): java.lang.IllegalArgumentException: Invalid Query. You cannot use 'not_in' filters with 'array_contains' filters.


I tried also like this

 await FirebaseFirestore.instance
                .collection('videos')
                .where('Hashtagsforallvideos', arrayContains: widget.hashtag)
                .limit(15)
                .get()
                .then((value) => {
                      if (value.docs.isNotEmpty)
                        {
                          value.docs.forEach((doc) {
                            if (doc.data()['uid']) {
                            } else {}
                            // doc.data() is never undefined for query doc snapshots
                          }),
                        }

CodePudding user response:

The error is quite clear:

You cannot use 'not_in' filters with 'array_contains' filters.

You cannot combine these two clauses in a query:

.where('uid', whereNotIn: listOfIds)
.where('Hashtagsforallvideos', arrayContains: widget.hashtag)

From the documentation on query limitatioms:

You can use at most one array-contains clause per query. You can't combine array-contains with array-contains-any.

You can use at most one in, not-in, or array-contains-any clause per query. You can't combine in , not-in, and array-contains-any in the same query.

If you need to filter by both these conditions, you will have to perform one in the query and the other one in your application code.

  • Related