[英]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.