Reputation: 622
long story short that I have a collection called products , in this collection every product have a document that is called category , I want to get all the products with the same category and this is the structure for it . I know that I should use where().equalto
, but I did not get it , any help ?
Upvotes: 0
Views: 1381
Reputation: 1313
Future<List<ProductModel>> getProductCategory(String category) async {
QuerySnapshot query = await _firestore.collection(collection)
.where("category", isEqualTo: category)
.get();
if(query.docs.isNotEmpty){
query.docs.forEach((element) {
productCategory.add(ProductModel.fromSnapshot(element.data()));
});
}
return productCategory;
}
This will return all documents which having category is equal to "eye".
Upvotes: 2