Firebase Firestore where operator uses nested dynamic properties
P粉052686710
P粉052686710 2023-09-08 16:06:57
0
1
569

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粉052686710
P粉052686710

reply all(1)
P粉495955986

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")
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template