Luca_54
Luca_54

Reputation: 539

Firebase check if item is not in array in Flutter

I want to check in my Flutter app if an item is not in an array. If it is in it I want to sort it out, if not I want to take it.

There is an arrayContains function for the reverse function, but I couldn't find an arrayContainsNot function or something. How can I solve this?

I want to do it like this:

await FirebaseFirestore.instance
    .collection("someCollection")
    .where("someArray", arrayContainsNot: "someItem")
    .get();

Upvotes: 2

Views: 1357

Answers (1)

Victor Eronmosele
Victor Eronmosele

Reputation: 7686

You can use the not-in operator.

A not-in query returns documents where the given field exists, is not null, and does not match any of the comparison values.

So your code becomes:

    await FirebaseFirestore.instance
        .collection("someCollection")
        .where("someArray", whereNotIn: ["someItem"])
        .get();

Note that it supports up to 10 comparison values which have to be passed in a list to the whereNotIn property.

Upvotes: 6

Related Questions