Reputation: 17
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
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
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