Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore query using an object element as parameter

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

enter image description here

like image 836
frankybboy Avatar asked Nov 07 '17 22:11

frankybboy


People also ask

Can you query firestore?

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.

What is a Subcollection in firestore?

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.

How do you get a collection inside a document in firestore?

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().


2 Answers

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

like image 179
frankybboy Avatar answered Sep 28 '22 02:09

frankybboy


Here is the answer :

.where(new firestore.FieldPath('exObject' , 'dataToQuery'), '==', "value"))

More info Here

like image 41
BorisD Avatar answered Sep 28 '22 00:09

BorisD