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

96
Vistas
how to use variable in firestore query

I use firebase firestore db. This project have two main collection "securecollection" and "publiccollection". The securecollection is where all important data is stored and only accessible to authenticated users. But in order for some information to be visible to guest users, I am copying them into the publiccollection. Then, I want to save the id of this newly created public document in the secure document.

When I write a variable db.collection('securecollection').doc(secureDocid).update({ inside the query sentence, I get this error:

Uncaught (in promise) TypeError: o.indexOf is not a function

If I write the id as text db.collection('securecollection').doc('7llDqIWlmE5VM69Zzle2').update({, the code works.

Here is my code:

function toggleOlustur(secureDocid) {
  const db = firebase.firestore();
  db.collection("securecollection").get()
    .then(querySnapshot => {
      querySnapshot.forEach(doc => {
        if (doc.id == secureDocid) {
          db.collection("publiccollection").add({
              oad: doc.data().oad,
              osad: doc.data().osad,
              opuan: doc.data().opuan,
              odtarih: doc.data().odtarih,
              odurum: "1",
            })
            .then((docRef) => {
              db.collection('securecollection').doc(secureDocid).update({
                preference: docRef.id
              })
            });
        }
      });
    });
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The doc() method expects a string argument, and from the error message it sounds like your secureDocid is not a string value. If you console.log(JSON.stringify(secureDocid)) you can see what it outputs, which might help to figure out the problem.

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