子集合是创建玩家“朋友列表”的最佳方法吗?

问题描述 投票:1回答:1

我很难处理子集合(这是我的第一个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,
    });
  }
firebase flutter google-cloud-firestore
1个回答
0
投票
您可以像这样在

document内创建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, }); }
© www.soinside.com 2019 - 2024. All rights reserved.