3

To Query from Firebase Firestore documents by using properties of objects.

My Data Structure :

document{  
  id:"document-id",
  user: {
    name:"John",
    email:"example@gmail.com"
  }
}

How to query from a collection in which I want documents having "example@gmail.com" as email address of user.

Note:
This question is similar to this one : Firestore: Query documents by property of object
But, that question is for backend(node) and this one is for frontend(java).

Abhimanyu
  • 11,351
  • 7
  • 51
  • 121

1 Answers1

6

The key is to use Dot operator for objects to access attributes, just as we use in normal java programs.

Example:

FirebaseFirestore.getInstance().collection("collection_name")
        .whereEqualTo("user.email", "example@gmail.com");
Abhimanyu
  • 11,351
  • 7
  • 51
  • 121