再次删除带有文档和集合的集合(firestore react native)
delete a collection with document and collection again inside (firestore react native)
我在 firestore 上删除时遇到问题
这是我的删除
var chatId = route.params.number; // +639266825843
var docRef = firestore().collection('ChatRoom').doc(chatId).collection('messages');
docRef.doc(chatId).delete();
但每次我尝试删除时都没有任何反应。完全没有错误。
这就是我设置该集合的方式
firestore().collection('ChatRoom')
.doc(id)
.collection('messages')
.add({...myMsg, createdAt:firestore.FieldValue.serverTimestamp()})
如果要删除messages
(子)集合的所有文档,需要查询集合并删除每个文档,例如使用Promise.all()
or by using a batched write(仅包含删除)
var chatId = route.params.number; // +639266825843
var colRef = firestore()
.collection('ChatRoom')
.doc(chatId)
.collection('messages');
colRef.get().then((querySnapshot) => {
Promise.all(querySnapshot.docs.map((d) => d.ref.delete()));
});
QuerySnapshot
returns QueryDocumentSnapshot
数组的 docs
属性。
此外,查看您的 +639266825843
文档如何以 italic 字体显示:这意味着,在控制台中,该文档仅显示为“一个或多个子集合的容器”,但它不是“真正的”文件。它不存在,因为您从未创建过它,您只是在其子集合之一中创建了文档。更多详情 .
我在 firestore 上删除时遇到问题
这是我的删除
var chatId = route.params.number; // +639266825843
var docRef = firestore().collection('ChatRoom').doc(chatId).collection('messages');
docRef.doc(chatId).delete();
但每次我尝试删除时都没有任何反应。完全没有错误。
这就是我设置该集合的方式
firestore().collection('ChatRoom')
.doc(id)
.collection('messages')
.add({...myMsg, createdAt:firestore.FieldValue.serverTimestamp()})
如果要删除messages
(子)集合的所有文档,需要查询集合并删除每个文档,例如使用Promise.all()
or by using a batched write(仅包含删除)
var chatId = route.params.number; // +639266825843
var colRef = firestore()
.collection('ChatRoom')
.doc(chatId)
.collection('messages');
colRef.get().then((querySnapshot) => {
Promise.all(querySnapshot.docs.map((d) => d.ref.delete()));
});
QuerySnapshot
returns QueryDocumentSnapshot
数组的 docs
属性。
此外,查看您的 +639266825843
文档如何以 italic 字体显示:这意味着,在控制台中,该文档仅显示为“一个或多个子集合的容器”,但它不是“真正的”文件。它不存在,因为您从未创建过它,您只是在其子集合之一中创建了文档。更多详情