简体   繁体   English

如何在 Firestore -Flutter 中将所有文档从一个集合复制到另一个集合?

[英]How to copy all documents from one collection to other in Firestore -Flutter?

I am in a situation where when a users makes a payment, his cart products Stored in Firestore collection (CartProducts) should be moved to new collection Called SuccessFullOrders .我的情况是,当用户付款时,他存储在 Firestore 集合(CartProducts)中的购物车产品应移动到名为SuccessFullOrders的新集合中。

So my Basic Question is how to move all documents from one collection to Firestore other Collection in Flutter所以我的基本问题是如何将所有文档从一个集合移动到 Flutter 中的 Firestore 其他集合

I don't Know how to write code for this in flutter.Thanks for your Answers我不知道如何在 flutter 中为此编写代码。感谢您的回答

Here's my Code这是我的代码

void _onPressed()async {
  final FirebaseAuth _auth = FirebaseAuth.instance;

  FirebaseUser user = await _auth.currentUser();
  print(user.uid);
  firestorInstance.collection("users").getDocuments().then((querySnapshot) {
    querySnapshot.documents.forEach((result) {
      firestorInstance.collection("users").document(user.uid).collection("CartProducts").getDocuments().then((querySnapshot) {
        querySnapshot.documents.forEach((result) {

          //what to write here so that new documents would be created in other collection 

          print(result.data);
        });
      });
    });
  });
}

Currently there's no way to copy a collection into another provided by firebase officially.目前没有办法将一个集合复制到另一个firebase官方提供的集合中。 And, for sure, you can iterate over your previous collection & create new documents in the other.而且,当然,您可以迭代以前的集合并在另一个集合中创建新文档。

In your case you should be doing something like:在您的情况下,您应该执行以下操作:

userFirebaseInstance
    .collection(NewCollection)
    .document()
    .setData(YourDataHere)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Flutter 删除 Firestore 中集合中的所有文档 - How to Delete all documents in collection in Firestore with Flutter 如何仅将文档从一个集合复制到另一个集合一次 Flutter Firebase - How can I copy documents from one collection to the other only once Flutter Firebase 从 Firestore 的一个集合中获取所有文档 - Getting all documents from one collection in Firestore 如何从保存在另一个集合中的 id 作为 flutter firestore 中的文档检索存储在一个集合中的文档 - How to retrieve documents stored in one collection from the ids saved in another collection as documents in flutter firestore 如何从Firestore中的集合中检索所有文档? - How to retrieve all documents from a collection in Firestore? 从云 Firestore 中的一个集合中获取所有文档? - Getting all documents from one collection in cloud Firestore? Flutter 和 Firestore:如何从集合组更新多个特定文档 - Flutter and Firestore: How to update multiple specific documents from collection group 如何从 Firestore 的集合中获取所有文档 - How to get all documents from a collection from Firestore 使用 firebase 云功能将所有文档从 Firestore 中的主集合复制到新的子集合 - Using firebase cloud function to copy all documents from a master collection in Firestore to new sub-collection 如何列出用户可以从 Firestore 集合中读取的所有文档? - How to list all documents the user can read from a Firestore collection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM