Home > Mobile >  Firebase deletes the hole collection although specify the document id
Firebase deletes the hole collection although specify the document id

Time:05-14

iam using flutter and firebase to develop an app.

My Firebase collection/subcollection structure is the following:

collection(likes)-> doc(ownerId)->subcollection(likesList).doc(likeId){Data}

I wanna delete one like/doc out of the subcollection "likesList" using the likeId with this code:

final CollectionReference likesRef = FirebaseFirestore.instance.collection('likes');

Future deleteLike(String ownerId,String likeId)async{await likesRef.doc(ownerId).collection("likeList").doc(likeId).delete();}

This code deletes the complete likes-collection and i don`t understand why.

In my project are the latest package/flutter versions installed.

Let me know if i forget something, Thank you in advance!

CodePudding user response:

A collection can't exist without an document in it. So if you delete the last document in a collection, the collection is automatically removed. Maybe you are deleting the last document in the collection?

  • Related