我有两个馆藏,一个是普通馆藏,另一个是第一个馆藏的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();
但没有结果,我不知道如何仅获取具有特定引用文献的文档。
我不想在authors集合中获得所有文档,
有人可以帮助我如何查询和仅获取特定文件吗?
最佳答案
我建议您看看这里已经回答的问题:
Finding all docs with specific reference in Cloud Firestore
看来,这与您的案件和解决方案非常相关,肯定可以为您提供帮助。 :)
让我知道链接是否对您有帮助!
关于firebase - 如何通过引用在Firestore中搜索文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60038577/