【发布时间】:2020-02-03 11:43:37
【问题描述】:
我有两个集合,一个是普通集合,另一个是第一个的 documentReference ,我想要做的是通过它的引用给我具体的文档, 我通过在 for 循环中搜索来找到特定的文档,但是有没有更好的方法来做到这一点,而不是从第一个集合中获取所有文档,只需获取我需要的唯一一个。
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;
}
我也试过这个,但什么也没给我
var snap = documentReference.get();
author_model m = author_model.map(snap);
print(m.author_name + ": " + m.author_education)
也试过这个查询
final QuerySnapshot querySnapshot = await authors.where('documentID', isEqualTo:
ref).getDocuments();
但没有结果,我不知道如何仅获取具有特定参考的文档。 我不想获取作者集合中的所有文档,
谁能帮我查询和获取特定文档吗?
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore