Firebase “子集合”是创建“子集合”的最佳方式吗;“友谊名单”;球员?
我在子集合方面遇到了困难(这是我的第一个Flatter/firebase/nosql项目) 我想在玩家集合中实现一个“好友列表”,我需要一个与好友列表中其他玩家的子集合,这是最好的方法吗?如果是,如何将子集合添加到文档中Firebase “子集合”是创建“子集合”的最佳方式吗;“友谊名单”;球员?,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我在子集合方面遇到了困难(这是我的第一个Flatter/firebase/nosql项目) 我想在玩家集合中实现一个“好友列表”,我需要一个与好友列表中其他玩家的子集合,这是最好的方法吗?如果是,如何将子集合添加到文档中 final CollectionReference playerCollection = Firestore.instance.collection('player'); Future updatePlayerData( String nickname,
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,
});
}
您可以像这样在文档中创建子集合
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,
});
}
您可以像这样在文档中创建子集合
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,
});
}
.collection(frdUid)
非常不寻常,通常是个坏主意。这样做的原因是您无法在客户端SDK中查询集合名称,因此您几乎总是使用硬编码的集合名称。一种更可能的惯用方法是.collection('friends').document(frdUid).
您是否像上面评论中所说的那样尝试过?如果是,我将更新我的答案.collection(frdUid)
非常不寻常,通常是个坏主意。这样做的原因是您无法在客户端SDK中查询集合名称,因此您几乎总是使用硬编码的集合名称。一种更可能的惯用方法是.collection('friends').document(frdUid).
您是否像上面评论中所说的那样尝试过?如果是,我会更新我的答案