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

152
Views
getDocs - firebase react native

I want to get a document and to update. I tried used this code, but he dont accept the "idDoc":

const Doc = query(collection(database, "user_veic"),where("email", "==", auth.currentUser?.email),where("kmF", "==", ""));
        getDocs(Doc).then((querySnapshot) => {
            querySnapshot.forEach((doc) => {
                console.log(`${doc.id} => ${doc.data()}`);
                const idDoc = doc.id
            })
        })
        .then(
            updateDoc(doc(database, "user_veic", idDoc), {
            kmF: "teste1",
            km: "teste1",
            }))

^^^^: FirebaseError: Invalid document reference. Document references must have an even number of segments, but user_veic has 1

I tried this:

const Doc = query(collection(database, "user_veic"),where("email", "==", auth.currentUser?.email),where("kmF", "==", ""));
        getDocs(Doc).then((querySnapshot) => {
            querySnapshot.forEach((doc) => {
                console.log(`${doc.id} => ${doc.data()}`);
                const idDoc = doc(database, "user_veic", doc.id)

                updateDoc(idDoc, {
                    kmF: "teste1",
                    km: "teste1",
                })
            })
        })

^^^^: [Unhandled promise rejection: TypeError: doc is not a function. (In 'doc(database, "user_veic", doc.id)', 'doc' is an instance of lh)]

What did i do wrong?

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

0

In your first code example, you declare const idDoc inside of the callback parameter to .forEach(). That variable does not exist outside of the callback function. You then try to use it in the updateDoc() in a completely different block of code. It is undefined at that point, thus you are getting an error that you aren't passing enough parameters.

In your second code example, which is much closer to what you want to do, based on the error message it looks like you aren't importing doc with the rest of the Firestore functions from firebase/firestore.

about 4 years ago · Juan Pablo Isaza Report

0

RESOLVIDO @Greg thank you

const Doc = query(collection(database, "user_veic"),where("email", "==", auth.currentUser?.email),where("kmF", "==", ""));

getDocs(Doc).then((querySnapshot) => {
    let values = null;
    querySnapshot.forEach((doc) => {
        console.log(`${doc.id} => ${doc.data()}`);
        values = doc.id;
    });

    var transactionUpdate = database.collection("user_veic").doc(values);
    transactionUpdate.update({
        kmF: kmF,
    })    
})
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!