I have two collection, one is normal collection , and the other one is holding the documentReference for the first one , what I want is to do is giving me the specific document by its reference , I find the specific document by searching in for loop, but is there any better way to do that , without geting all the document from the first collection , just get the only one that i need .
static Future<List<author_model>> getTHEauthor(DocumentReference documentReference) async{
String ref = documentReference.documentID;
DocumentReference dReference = articleCollection.document(documentReference.documentID);
List<author_model> author=[];
author_model model ;
final QuerySnapshot querySnapshot = await authors.getDocuments();
List<DocumentSnapshot> result = querySnapshot.documents;
for(int i=0 ; i<result.length ; i++) {
if (result[i].documentID == ref) {
model = new author_model(
result[i]['author_name'], result[i]['author_image'],
result[i]['author_work_exeperience']
, result[i]['autor_education']);
author.add(model);
break;
}
}
// print(author.length);
return author;
}
also I tried this one , but give me nothing
var snap = documentReference.get();
author_model m = author_model.map(snap);
print(m.author_name + ": " + m.author_education)
Also tried this query
final QuerySnapshot querySnapshot = await authors.where('documentID', isEqualTo:
ref).getDocuments();
but no result, I don't know how to get only the document with the specific reference. I don't want to get all the document in the authors collection ,
Can anyone help me to how to query and get only for the specific document , please ?