Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda