我正试图在Flutter应用中读取exp_date
的值,如下图所示:
字段/值对位于名为Card
的映射中,该映射位于名为sources
的子集合中。我可以通过将source集合的DocId(另一个docId是firebase用户uid)放入以下内容来读取值:
StreamBuilder(stream: Firestore.instance.collection('stripe_customers').document(userId).collection('sources').document('qRvDob75kTzhT3').snapshots(),builder: (context,snapshot){
if(!snapshot.hasData){
return new Text("Loading");
}
var userDocument = snapshot.data;
return new Text(userDocument["card"]['exp_year'].toString());
},),
但是显然这不是很实用。如何在不知道文档ID的情况下访问Card map值?
答案 0 :(得分:1)
有两种获取文档内容的方法:
如果您不知道#1所需的ID,则必须尝试#2。但是,由于您似乎没有办法过滤该集合中的文档,因此您将必须获取所有文档。出于可伸缩性目的,这可能不是您想要的。
考虑在编写文档之前要如何在Firestore中查找数据。