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

236
Vistas
FirebaseError: Function updateDoc() called with invalid data. serverTimestamp() is not currently supported inside arrays

I'm trying to update the document with the new comments array but I'm getting this error when I submit a new comment. In every document, there is an array(comments array) of object(single comment)

FirebaseError: Function updateDoc() called with invalid data. serverTimestamp() is not currently supported inside arrays (found in document solutions/wLflWVhLueEKjBBknHNi)

comment submit code:

const handleSubmit = async (e) => {
    e.preventDefault()

    try {
      const commentToAdd = {
        id: Math.floor(Math.random() * 10000),
        content: newComment.trim(),
        reactions: [],
        user: {
          userID: user.uid,
          avatarURL: user.photoURL,
          displayName: user.displayName,
          username: user.reloadUserInfo.screenName,
        },
        replies: [],
        createdAt: serverTimestamp(),
      }
      await updateDocument(id, {
        comments: [...solution.comments, commentToAdd],
      })
      setNewComment("")
      if (response) {
        console.log(response.error)
      }
    } catch (error) {
      console.log(error)
    }
  }

updateDocument hook code:

  const updateDocument = async (id, updates) => {
    console.log(JSON.stringify(updates))
    dispatch({ type: "IS_PENDING" })
    try {
      const updatedDocument = await updateDoc(doc(db, c, id), updates)
      dispatchIfNotCancelled({ type: "UPDATED_DOCUMENT", payload: updatedDocument })
      return updatedDocument
    } catch (error) {
      dispatchIfNotCancelled({ type: "ERROR", payload: error })
      return null
    }
  }

Anyone please help me with this.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of:

createdAt: serverTimestamp()

Use this:

createdAt: Timestamp.now()

You can find more info here

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