简体   繁体   English

再次删除带有文档和集合的集合(firestore react native)

[英]delete a collection with document and collection again inside (firestore react native)

I am having trouble deleting on firestore我在 firestore 上删除时遇到问题

在此处输入图像描述 在此处输入图像描述

here's my delete这是我的删除

var chatId = route.params.number; // +639266825843
var docRef = firestore().collection('ChatRoom').doc(chatId).collection('messages');
docRef.doc(chatId).delete();

but everytime i try to delete nothing happens.但每次我尝试删除时都没有任何反应。 There's no error at all.一点错误都没有。

this is how I set that collection这就是我设置该集合的方式

firestore().collection('ChatRoom')
.doc(id)
.collection('messages')
.add({...myMsg, createdAt:firestore.FieldValue.serverTimestamp()})

If you want to delete all the docs of the messages (sub)collection, you need to query the collection and delete each document, for example by using Promise.all() or by using a batched write (containing only deletions)如果要删除messages (子)集合的所有文档,则需要查询集合并删除每个文档,例如使用Promise.all()或使用批量写入(仅包含删除)

  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()));
  });

The docs property of the QuerySnapshot returns an array of QueryDocumentSnapshot s. QuerySnapshotdocs属性返回一个QueryDocumentSnapshot数组。


In addition, look at how your +639266825843 document is displayed in an italic font: this means, in the console, that this document is only present as "container" of one or more sub-collection(s) but that it is not a "genuine" document.此外,查看您的+639266825843文档如何以斜体显示:这意味着,在控制台中,该文档仅作为一个或多个子集合的“容器”存在,但它不是“真正的”文件。 It does not exist, because you never created it, you only created docs in one of its subcollections.它不存在,因为您从未创建过它,您只是在其子集合之一中创建了文档。 More detail here .更多细节在这里

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM