Skip to content Skip to sidebar Skip to footer

How To Query Data From Firestore With Dynamic Input

I have a problem with my code and I don't know how to solve it in the correct way. I am trying to write a filter that when user clicks on each filter, it will automatically query t

Solution 1:

You should only add to the query clause when needed (ie. type, currency, or location are true/not empty):

let query = firebase
    .firestore()
    .collection("ItemData");

if (type) {
    query = query.where('type', '==', type);
}

if (currency) {
    query = query.where('currency', '==', currency);
}

if (location) {
    query = query.where('location', '==', location);
}

Special thanks to this post which had a similar issue to yours.

Post a Comment for "How To Query Data From Firestore With Dynamic Input"