firebase - 子集合是创建玩家“好友列表”的最佳方式吗?
问题描述
我很难处理子集合(这是我的第一个颤振/firebase/nosql 项目)
我想在玩家集合中实现一个“朋友列表”,并且我需要一个与朋友列表中其他玩家的子集合,这是最好的方法吗?如果是,我如何将子集合添加到文档中?
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,
});
}
解决方案
你可以像这样在文档中创建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,
});
}
推荐阅读
- amazon-web-services - 无法将 AWS SAM CLI 从 0.2.8 升级到 0.6.1
- regex - 如何通过PowerShell检查字符串是否在多个地方包含一个字母\符号?
- wordpress - 无法读取未定义的属性“setDefaults”
- c# - 在运行时更改控件属性时禁用事件
- angularjs - 以角度将对象数组推送到 JSON
- java - Restlet 将带有 Post("xml") 的 422 返回到 DomRepresentation
- javascript - 如何从给定的年份和周中获取一周的开始日期和结束日期?
- perl - 使用“require”从远程服务器导入库 perl 脚本
- javascript - Braintree:用户可以更新他们保管的客户信息吗?
- java - 列中的空值 - Hibernate + Postgres