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

643
Views
" Uncaught (in promise) FirebaseError: Invalid document reference. Document references must have an even number of segments,but Users has 1." Reactjs

I am trying to get the data from firebase version9.8 in react.js project, but I am getting the error:

Uncaught (in promise) FirebaseError: Invalid document reference. Document references must have an even number of segments, but Users has 1.

how can I resolve this?

( I want to get the write the data in firebase on submit button so so i write the code in onSubmitHandler )

const onSubmitHandler = async (event) => {  
    console.log(event);
    console.log("saving data to database request is Trigered...")
    // Hear we push the data in firestore databae

    await setDoc(doc(db, "Users",), {

      name:collectionOfStates},{merge: true}


      
    ).then(() => console.log("Data Save in firebase")).catch((error) => {
      console.log(error);
    })

  }
about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

Your code tries to write data into the Users collection, instead of in a document under it, which is not possible.

If you want to write to a specific, known document, specify its document ID in the call to doc:

                      // ๐Ÿ‘‡
setDoc(doc(db, "Users", "idOfDoc"), {
  name:collectionOfStates},{merge: true}    
)

If you want to add a new document to the collection with an auto-generated ID, use addDoc instead of setDoc:

// ๐Ÿ‘‡
addDoc(doc(db, "Users"), {
  name:collectionOfStates},{merge: true}    
)
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!