I am getting the below error whilst running a Firestore query.
[firestore/invalid-argument] Client specified an invalid argument.
Note that this differs from failed-precondition. invalid-argument
indicates arguments that are problematic regardless of the state of
the system (e.g., an invalid field name).
Here is my query;
export async function getFilteredData(category, filters, city_id) {
let venues = [];
let lastVenue;
let query = firestore()
.collection("venues")
.where("active", "==", true)
.where("city_id", "==", city_id);
if (category) {
query = query.where("category.id", "==", category);
}
if (filters?.subcategories.length > 0) {
query = query.where("subcategory.id", "in", filters.subcategories);
}
if (filters?.districts.length > 0) {
query = query.where("district.id", "in", filters.districts);
}
if (filters?.prices.length > 0) {
console.log(filters.prices);
query = query.where("price", "in", filters.prices);
}
if (filters?.tags.length > 0) {
query = query.where("tags", "array-contains-any", filters.tags);
}
if (filters?.order) {
query = query.orderBy(filters.order, "desc");
} else {
query = query.orderBy("created_at", "desc");
}
await query
.limit(20)
.get()
.then((snapshot) => {
lastVenue = snapshot.docs[snapshot.docs.length - 1];
snapshot.forEach((doc) => {
venues.push({ id: doc.id, ...doc.data() });
});
});
return { venues, lastVenue };
}
This error is only returned when subcategories, districts or prices arrays total more than 12? – Can’t find in the documentation where this limitation is?
The limits are documented as:
Note the following limitations for in, not-in, and array-contains-any:
- Cloud Firestore provides support for logical OR queries through the or, in, and array-contains-any operators. These queries are limited to
30 disjunctions based on the query’s disjunctive normal form.- You can use at most one array-contains clause per disjunction (or group). You can’t combine array-contains with array-contains-any in
the same disjunction.- You can’t combine not-in with not equals !=.
- not-in supports up to 10 comparison values.
The issue is likely that you have more than a total of 30 “disjunctions” between all of your in
and array-contains-any
filters (subcategories, districts, prices, and tags), not just one of them alone.