19

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

4 Answers 4

31
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

Sign up to request clarification or add additional context in comments.

2 Comments

I realize this is a year old, but I'm working with the same .where method on firestore. I just don't know how to access the data returned. the Object returned shows the right id under the QuerySnapshot, but I don't see the actual object itself. How did you access the object it returns?
let theResults = dbRef.collection("Table").where("exObject.dataToQuery", "==", "value")
7

Here is the answer :

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

More info Here

1 Comment

Not the OP here, but thank you for sharing this. I think FieldPath is useful and yet underused.
0

Try ( change from 'Table' to 'TEST' )

xptoCollection : AngularFirestoreCollection<any>;

  constructor(private afs: AngularFirestore) { }

      this.xptoCollection = this.afs.collection('TEST', ref => {
        return ref.where('exObject.{dataToQuery}', '==', 'value');
      });

1 Comment

doesn't seem to do the trick, the query still returns 0 result
-4

for some reason to work , u need to leave space between object_name and .property_name

'exObject .dataToQuery'

instead of

 'exObject.dataToQuery'

leave space and it worked for me

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.