Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Firestore: An error occurred while parsing query arguments on using whereNotIn and arrayContains at the same query

My query is:

snapshot = await FirebaseFirestore.instance
          .collection('dialogs')
          .where('active', isEqualTo: true)
          .where('users', arrayContains: globals.user.userId)
          .where('readers', whereNotIn: [globals.user.userId])
          .orderBy('priority')
          .limit(1)
          .get();

I'm getting the above exception:

Unhandled Exception: [cloud_firestore/unknown] An error occurred while parsing query arguments, see native logs for more information.

I have found some notes on the official Firestore documentation:

  • You can use at most one in, not-in, or array-contains-any clause per query. You can't combine these operators in the same query.
  • You can't combine not-in with not equals !=.

All should be just fine in my case.

Also I have tried several things:

  • If I remove only the whereNotIn line, everything is just fine.
  • if I remove only the arrayContains line, everything is just fine.

Why am I getting a query parsing exception? Thanks

like image 500
genericUser Avatar asked Oct 27 '22 13:10

genericUser


1 Answers

TL;DR

Firestore query documentation was not up to date (relevant for 04.04.21).

More details

I have checked my android Logchats on android studio and found out that:

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

While firebase documentation says that:

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

It was not mentioned on the Firebase documentation that array-contains cannot be at the same query along with not-in.

Conclusion

If you are encountered with query parsing exception. The most updated and fastest way to get relevant information about the problem is to check your Logchats.

like image 51
genericUser Avatar answered Nov 17 '22 07:11

genericUser