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

265
Vistas
Why isn't doc.data() a function in this if-statement?

When I remove the if-stament I get the data and doc.data() works, but I need to check for type 'added' so I don't output existing data again and again.

With the if-statement, I get this error message:

Uncaught TypeError: doc.data is not a function

 async getChats(callback){
    const roomFilter = query(colRef, where("room", "==", this.room));
    const ordered = query(roomFilter, orderBy('created_at'));
    this.unsub = onSnapshot(ordered, (snapshot) => {
      let items = []
      snapshot.docChanges().forEach(doc => {
        if(doc.type === 'added'){
          items.push({ ...doc.data(), id: doc.id })
          console.log(items);
          callback(items);
      }})    
    });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

snapshot.docChanges().forEach(doc => {

The variable you've called doc is more than just the document. It has additional information about the change. With the variable name you've chosen you need to do:

items.push({ ...doc.doc.data(), id: doc.doc.id })

I'd consider renaming it though, maybe to "change"

snapshot.docChanges().forEach(change => {
  if (change.type === 'added') {
    items.push({ ...change.doc.data(), id: change.doc.id })
    console.log(items);
    callback(items);
  }
})
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