我很难处理子集合(这是我的第一个flutter / firebase / nosql项目)
我想在玩家收藏夹中实现一个“好友列表”,并且我需要在friendList中与其他玩家收藏一个子收藏夹,这是最好的方法吗?如果是,如何将子集合添加到文档中?
final CollectionReference playerCollection =
Firestore.instance.collection('player');
Future updatePlayerData(
String nickname,
int gamesWon,
int points,
) async {
return await playerCollection.document(uid).setData({
"nickname": nickname,
"gamesWon": gamesWon,
"points": points,
});
}
答案 0 :(得分:0)
您可以像这样在文档中创建 subCollection ,
final CollectionReference playerCollection =
Firestore.instance.collection('player');
Future updatePlayerData(
String nickname,
int gamesWon,
int points,
) async {
return await playerCollection.document(uid).collection(frdUid).document(frdUid).setData({
//frdUid is unique id
"nickname": nickname,
"gamesWon": gamesWon,
"points": points,
});
}