Hey I am making a firebase database call that looks like this:
db.collection("posts").where("location", "==", location)
.get().then((querySnapshot) => {
[...]
})
The user can specify from what countries he would like to get posts (the .where() method is for that). But he can also pick all the countries, so in that case the method is no longer needed. Is there a way to add methods dynamically?
Something like this:
db.collection("posts")if(location != "all"){.where("location", "==", location)}
.get().then((querySnapshot) => {
[...]
})
let query = db.collection(...); if (...) query = query.where(...); query.get().then(...)