I have these documents inside the collection.
Document 1
Document 2
For every document in these collections, these items of the map would have different values. Is it possible to query those items that have a number below 5?
For example:
And then for the description 2:
So far, this is what I have done:
const getData = async () => {
const querySnapshot = await getDocs(collection(db, "collectionDesc"));
const q = query(querySnapshot, where("map", "<=", 5));
const arr = [];
querySnapshot.forEach((doc) => {
arr.push({
...doc.data(),
id: doc.id,
});
});
if (isMounted) {
console.log(arr)
}
};
As b2m9 commented, this is not possible as your query compares the map field to the primitive value 5 you pass, which will never be equal.
To implement this use-case, you'll have to add additional data to your document, like a field that tracks the lowest value in the map field. Say you call this lowestValueInMap and its value is 4 based on your sample document, you can then query it with:
query(querySnapshot, where("lowestValueInMap", "<=", 5));