firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.63k stars 3.95k forks source link

[cloud_firestore]: Filter does not support isEqualTo null. #13352

Open danReynolds opened 2 days ago

danReynolds commented 2 days ago

Is there an existing issue for this?

Which plugins are affected?

Core, Database

Which platforms are affected?

iOS

Description

Filtering by isEqualTo: null works off of a CollectionReference like:

FirebaseFirestore.instance.collection('users').where('name', isEqualTo: null); // Returns documents with no name field.

But this is not supported using a Filter since it makes an assertion that exactly one field is not null.

FirebaseFirestore.instance.collection('users').where(Filter('name', isEqualTo: null)); // Throws assertion error.

I would expect that these two queries have the same behavior.

Reproducing the issue

N/A

Firebase Core version

2.27.0

Flutter Version

3.19.0

Relevant Log Output

No response

Flutter dependencies

Expand Flutter dependencies snippet
```yaml Replace this line with the contents of your `flutter pub deps -- --style=compact`. ```

Additional context and comments

No response

SelaseKay commented 1 day ago

This behavior is expected because isEqualTo defaults to null. The assertion is there to prompt you to provide a value rather than using null. FirebaseFirestore.instance.collection('users').where('name', isEqualTo: null); on the other hand does not throw an error, but it's redundant. Since isEqualTo is null by default, this is equivalent to not applying the where clause at all.