0

i recently began to use firebase and i ran into a problem, to get it straight, i want to make a e-commerce site, ofcourse it has cart, i used firebase for my back-end, for every user, i create a document in "users" collection, each user's document id is the uid of that given user. On every document, i have a cart, and in the cart, the products, on my cart page, i want to have a "Empty Cart" that deletes all the products, meaning it deletes "cart" collection. How can i do that? I have left some photos below that will probably explain the problem better.

Image of the firebase tree

I tried this and it did not work!

const deleteCart = async () => {
    const cartDoc = `users/${user.uid}/cart`
    
    await deleteDoc(db, cartDoc)
    
    }

i get this error : " TypeError: Cannot use 'in' operator to search for '_delegate' in undefined "

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • If you want to delete a collection or subcollection from your app code, you will have to query for all the documents, then delete them individually. – Doug Stevenson Jan 24 '23 at 19:00
  • How can i do that, im not really sure how? @DougStevenson – Burduja Alexandru Jan 24 '23 at 19:57
  • This question has two marked duplicates. Look at those. All you will do are three things that are covered in the documentation and plenty of example code: 1. query the collection 2. iterate teh documents 3. delete each one in that loop. – Doug Stevenson Jan 24 '23 at 20:02
  • @DougStevenson they are all with old syntaxes that don't work with firebase version 9, for example, ref.doc.delete(), doesn't exist anymore, but okey.. :) – Burduja Alexandru Jan 24 '23 at 20:21
  • The Firebase documentation explains how to do each one of those three things. If you get stuck on one of them, post a new question with the code you tried that doesn't work the way you expect. – Doug Stevenson Jan 24 '23 at 20:45

0 Answers0