Firebase 将文档添加到Cloud Firestore中的集合,而不覆盖以前的文档

Firebase 将文档添加到Cloud Firestore中的集合,而不覆盖以前的文档,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,在我的颤振应用程序中,我需要将文档添加到集合“影响者帖子”中,并且每次用户添加新的“帖子”时,该文档都必须添加到以前的。。。但在这一刻,我只是得到了上一个文件的覆盖。 正如您通过我的方法所看到的,我有uploadImagefuture 它拾取图像并将其存储到Firebase的存储器中。 之后,我创建了一个名为influencerPost的集合,每次发布新帖子时,我都必须添加该集合以生成新文档而不覆盖 这是完整的代码: Future uploadImage(BuildContext context

在我的颤振应用程序中,我需要将文档添加到集合“影响者帖子”中,并且每次用户添加新的“帖子”时,该文档都必须添加到以前的。。。但在这一刻,我只是得到了上一个文件的覆盖。 正如您通过我的方法所看到的,我有
uploadImage
future 它拾取图像并将其存储到Firebase的存储器中。 之后,我创建了一个名为
influencerPost
的集合,每次发布新帖子时,我都必须添加该集合以生成新文档而不覆盖

这是完整的代码:

Future uploadImage(BuildContext context) async {
    String fileName = basename(_postImage.path);
    Reference firebaseStorageRef =
        FirebaseStorage.instance.ref().child('postImage/$fileName');
    UploadTask uploadTask = firebaseStorageRef.putFile(_postImage);
    TaskSnapshot taskSnapshot = await uploadTask.whenComplete(() => null);
    final String downloadUrl = await taskSnapshot.ref.getDownloadURL();
    await FirebaseFirestore.instance
        .collection('influencerPost')
        .doc(firebaseUser.uid)
        .set({
      "imageUrl": downloadUrl,
      'postText': IfUserProfile.post
    });
    setState(() => CircularProgressIndicator());
  }

通过这种方式,我获得了除文档外的所有内容,而我需要保留以前的内容并添加一个新内容。

因为您要针对用户维护多篇文章,所以必须创建子集合。检查下面我添加子集合的代码。集合(“post”)


谢谢,要从云firestore中获取它,需要指定影响者帖子/帖子路径,对吗?
    Future uploadImage(BuildContext context) async {
    String fileName = basename(_postImage.path);
    Reference firebaseStorageRef =
        FirebaseStorage.instance.ref().child('postImage/$fileName');
    UploadTask uploadTask = firebaseStorageRef.putFile(_postImage);
    TaskSnapshot taskSnapshot = await uploadTask.whenComplete(() => null);
    final String downloadUrl = await taskSnapshot.ref.getDownloadURL();
    await FirebaseFirestore.instance
        .collection('influencerPost')
        .doc(firebaseUser.uid)
        .collection("post")
        .add({
      "imageUrl": downloadUrl,
      'postText': IfUserProfile.post
    });
    setState(() => CircularProgressIndicator());
  }