i'm using Firestore as my database in a project and i have a table that i need to do a query inside an object
{
foo: "data",
bar: "data",
exObject: {
dataToQuery: "value"
}
}
here is an example of a structure where i want to do a query inside the object a query that would look like this:
dbRef.collection("Table").where("exObject.dataToQuery", "==", "value")
but this is not working.
Is there a way to query in Firestore using an object's inner value as parameter? If not, is there a way to achieve something that would give the same result?
Example of a Firestore Structure
Cloud Firestore provides powerful query functionality for specifying which documents you want to retrieve from a collection or collection group. These queries can also be used with either get() or addSnapshotListener() , as described in Get Data and Get Realtime Updates.
A subcollection is a collection associated with a specific document. Note: You can query across subcollections with the same collection ID by using Collection Group Queries. You can create a subcollection called messages for every room document in your rooms collection: collections_bookmark rooms. class roomA.
We use the data parameter to get docPath , the value of the Firestore document path (slash-separated). This value is passed from the client calling the Cloud Function (see below). We then call the asynchronous listCollections() method on the DocumentReference created by using docPath (i.e. admin. firestore().
dbRef.collection("Table").where("exObject.dataToQuery", "==", "value")
this syntax i first posted is indeed the good syntax and started working eventually. I'd class the reason of my problem as a typo that i must have corrected trying a lot of different things
Here is the answer :
.where(new firestore.FieldPath('exObject' , 'dataToQuery'), '==', "value"))
More info Here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With