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

242
Views
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 answers
Answer question

0

Instead of:

createdAt: serverTimestamp()

Use this:

createdAt: Timestamp.now()

You can find more info here

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!