Deizo
Deizo

Reputation: 17

Cloud Firestore CollectionReference query field

I'm using Flutter and Firebase Cloud Firestore. Please, how can I query a CollectionReference by a field? Like:

* database
** collection
*** document
**** field (string) to query

Upvotes: 1

Views: 1125

Answers (2)

Christopher Natan
Christopher Natan

Reputation: 111

I am using this and it works

CollectionReference getRecord() {
    try {
      CollectionReference collectionReference = Firestore.instance.collection("collection-one").document("document one").collection("collection-two").where('field name', isEqualTo: 'string value');
      return collectionReference;
    } catch (e) {
      print('throw:' + e);
      return null;
    }
  }

Upvotes: 0

Rubens Melo
Rubens Melo

Reputation: 3315

You have to query your collection using where method. Then, you get all documents that match the criteria.

firestore.collection('myCollection').where('yourField', isEqualTo: 'any');

Upvotes: 2

Related Questions