【问题标题】:How to move the whole sub-collection in Cloud Firestore using flutter?如何使用颤振移动 Cloud Firestore 中的整个子集合?
【发布时间】:2019-09-21 18:04:09
【问题描述】:

我知道要移动文档,我们必须复制和粘贴。但是从复制->粘贴中丢失了子集合。

那么如何复制和粘贴集合中的所有文档?

来自路径 - /main/issueOpen/list/-Lb2yhvNLN6NsvCXAGyM/chat/[有很多文档]

到路径 - /main/issueClosed/list/-Lb2yhvNLN6NsvCXAGyM/chat/[全部移到这里]

...
    Future<Null> closeIssue() async {
        DocumentReference fromDocument = await Firestore.instance
            .collection("main").document("issueOpen").collection("list")
            .document(chatId);
        DocumentReference toDocument = await Firestore.instance
            .collection("main").document("issueClosed").collection("list")
            .document(chatId);
        fromDocument.get().then((datasnapshot) {
          if (datasnapshot.exists) {
            toDocument.setData(datasnapshot.data).whenComplete(() {
            }).catchError((e) => print(e));
          }
        });
      }
...

【问题讨论】:

    标签: firebase flutter google-cloud-firestore


    【解决方案1】:

    Firestore 中的所有读取操作都很浅。读取文档,不会从该文档的子集合中读取任何数据。

    这意味着要将文档及其子集合移动到新位置,您必须复制该文档并复制其子集合中的所有文档。

    如果文档的数量不太大,可以考虑在事务中执行此操作,以便它在服务器上自动发生。

    【讨论】:

      猜你喜欢
      • 2021-11-25
      • 1970-01-01
      • 2020-12-25
      • 1970-01-01
      • 2019-01-09
      • 2022-08-20
      • 1970-01-01
      • 2021-04-22
      • 1970-01-01
      相关资源
      最近更新 更多