我正在像这样将帖子添加到我的帖子集合中,但在这些帖子中,我想与它们一起添加一个名为“评级”的子集合。所以每个帖子都可以有一个不同的评级子集合。请帮忙。
final FirebaseAuth _auth = FirebaseAuth.instance;
final CollectionReference postsCollection =
FirebaseFirestore.instance.collection("posts");
final CollectionReference userCollection =
FirebaseFirestore.instance.collection("users");
Future addPost(
String title,
) async {
DocumentSnapshot<Map<String, dynamic>> userData =
await userCollection.doc(_auth.currentUser.uid).get();
return await postsCollection.doc().set({
"id": _auth.currentUser.uid,
"title": title,
"star": 0,
"date": FieldValue.serverTimestamp(),
"postid": userData.data()["city"].toString() +
_auth.currentUser.uid +
price +
rand.nextInt(10000).toString(),
});
}