【发布时间】:2020-01-28 19:22:24
【问题描述】:
我有一个拥有不同投资组合的用户列表。每个投资组合都具有相同的属性,但也是一组投资。应该是这样的:
Map user = {
"name": "John",
"portfolios": [ // collection
{
"title": "My portfolio 1",
"investments": [ // collection
{"title": "My investment 1.2"},
{"title": "My investment 1.2"}
]
},
{
"title": "My portfolio 2",
"investments": [ // collection
{"title": "My investment 2.1"},
{"title": "My investment 2.2"},
{"title": "My investment 2.3"}
]
}
]
};
为了获得我的作品集,我会这样做:
Future getMyPortfolios() async {
final userId = await authService.getUserId();
final portfolios = await Firestore.instance
.collection('users')
.document(userId)
.collection('portfolios')
.getDocuments();
return portfolios.documents;
}
但这只会返回带有标题的投资组合,而不是带有投资的内部集合。
我可以使用这些 ID 进行另一个呼叫,但我想知道是否有更快的方法并从该特定用户那里获取所有信息。
【问题讨论】:
标签: firebase flutter google-cloud-firestore