Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

373
Views
Uncaught (in promise) FirebaseError: Invalid collection reference. Collection references must have an odd number of segments

I am getting the error

    Uncaught (in promise) FirebaseError: Invalid collection reference. Collection references must have an odd number of segments, but 
Accounts/sKnjAQzJ1sQ5qRC4ki6b/RequestsReceived/m27vTB22izq6UixWP2s6 has 4.

My code is

var ref2 = collection(db, "Accounts/" + localStorage.getItem('Id') + "/RequestsReceived", id);
    const docRef2 = await getDoc(ref2);
    await deleteDoc (ref2);

The document I want to delete has the URL /Accounts/sKnjAQzJ1sQ5qRC4ki6b/RequestsReceived/m27vTB22izq6UixWP2s6

I understand that if you add a document, it has to have an odd number of path, the collection name, or collection/document/collection. But shouldn't deleteDoc have an even amount because I'm deleting collection/document or collection/document/collection/document. What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

"Accounts/" + localStorage.getItem('Id') + "/RequestsReceived", id

This path is pointing towards a document in 'RequestsReceived' sub-collection. So you should be using doc() to create a DocumentReference.

Also you don't need to fetch a document before deleting as long as you have the reference:

// ensure all values are defined
console.log(localStorage.getItem('Id'), id);

// use doc()
var ref2 = doc(db, "Accounts/" + localStorage.getItem('Id') + "/RequestsReceived", id);

await deleteDoc(ref2);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!