![](/img/trans.png)
[英]How to Delete all documents in collection in Firestore with Flutter
[英]How to copy all documents from one collection to other in Firestore -Flutter?
我的情况是,当用户付款时,他存储在 Firestore 集合(CartProducts)中的购物车产品应移动到名为SuccessFullOrders的新集合中。
所以我的基本问题是如何将所有文档从一个集合移动到 Flutter 中的 Firestore 其他集合
我不知道如何在 flutter 中为此编写代码。感谢您的回答
这是我的代码
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);
});
});
});
});
}
目前没有办法将一个集合复制到另一个firebase
官方提供的集合中。 而且,当然,您可以迭代以前的集合并在另一个集合中创建新文档。
在您的情况下,您应该执行以下操作:
userFirebaseInstance
.collection(NewCollection)
.document()
.setData(YourDataHere)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.