Delete document using firebase V9

907 views
Skip to first unread message

Cynthia Heyman

unread,
Sep 13, 2021, 12:47:08 PM9/13/21
to fireba...@googlegroups.com

I am trying to delete a document using the new firebase V9 and I am not sure what the syntax should be. 

The example from the firebase documentation doesn't include information about how to delete a document based on the document ID, which I need to do.  

The code I am attempting to use is this:
deleteDoc(doc(db, theDocument.id))

but I get this error:
runtime-core.esm-bundler.js?9e79:7053 Uncaught FirebaseError: Invalid document reference. Document references must have an even number of segments, but rkv has 1.

the rkv is the document id, so it is accurately pulling the id of the document I want to delete.  But it's not performing the delete, it's throwing the error.

Would love some help thanks.



Frank van Puffelen

unread,
Sep 13, 2021, 12:49:01 PM9/13/21
to Firebase Google Group
Hey Cynthia,

You're missing the collection that you want to delete the document from, so your theDocument.id is being interpreted as a collection name.

The simplest fix is:

deleteDoc(doc(db, "your collection name", theDocument.id))

Reply all
Reply to author
Forward
0 new messages