1

If I have a collection like this:

Logos:
  Logo1:
   colors: ["red","black"]
   shapes: ["square","circle"]
  Logo2:
   colors: ["red","yellow"]
   shapes: ["square"]

And if I want to search logos that are red or black, I would do the following:

db.collection("Logos").where("colors", "array-contains-any", ["red", "black"]).get().then((querySnapshot) => {
        //do stuff
    })

And that would get me all the Logos in my collection that contain the color red or black. However, how would I be able to do a search for logos that are (red OR black) AND (circle OR square) but I cannot combine multiple array-contains-any operators.

Is this even possible in Cloud Firestore? If not is there any alternative way to do this?

1 Answer 1

3

From the Firestore documentation:

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.

The workaround is to combine the values you want to check on into a single array, but I don't think that'll work here since you'd then be looking to combine AND and OR conditions on that array.

So the only option seems to be to perform one condition directly on the database, and do the rest of the filtering in your application code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.