Home  >  Q&A  >  body text

Firebase Firestore where operator uses nested dynamic properties

Using the model below, I need to use the where operator when querying Firestore. However, the where attribute is nested based on the following variable code:

where("category", "==", "Something"),

model

const language = "EN"

{ 
    EN: {
        category: "Something in english"
    },
    FR: {
        category: "Something in french"
    }
}
P粉052686710P粉052686710431 days ago544

reply all(1)I'll reply

  • P粉495955986

    P粉4959559862023-09-09 10:20:34

    To be able to query a collection based on the values ​​present in the map, you should use the where function call like this:

    where("EN.category", "==", "Some Category")

    If you need to change the language, then you should consider using variables instead of hard-coded values. In code it should look like this:

    where('${language}.category', "==", "Some Category")

    reply
    0
  • Cancelreply