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

300
Views
¿Cómo puedo actualizar una matriz anidada en Firestore?

mi base de datos en este momento

¿Hay alguna manera de actualizar los Me gusta y las respuestas con firebase firestore?

He llegado a ese momento en que presiono me gusta en un solo comentario pero solo tengo la referencia al documento de toda la publicación, por lo que no tengo una referencia a los comentarios en sí. También llegué al comentario con el método de búsqueda de las matrices, pero no es una referencia, es el comentario en sí.

Gracias de antemano, estoy pensando que solo tengo que reconsiderar cómo estructuro mi base de datos usando firestore.

 const addLikeToComment = async ( postID: string, commentID: string, userID: string ): Promise<void> => { const currentPost = await getPostById(postID) const currentPostDocId = currentPost[0].docID! const currentPostRef = doc(db, 'posts', currentPostDocId) const commentToAddLikeTo = currentPost[0].comments.find( (currComment) => currComment.commentID === commentID ) console.log(commentToAddLikeTo) if (!commentToAddLikeTo?.likes.includes(userID)) { await updateDoc(currentPostRef, { // add the like to comments - currentComment - likes array inside it push the userID }) } else { await updateDoc(currentPostRef, { // remove the like }) } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

const addLikeToComment = async ( postID: string, commentID: string, userID: string ): Promise<void> => { const currentPost = await getPostById(postID) const currentPostDocId = currentPost[0].docID! const currentPostRef = doc(db, 'posts', currentPostDocId) const commentToAddLikeTo = currentPost[0].comments.find( (currComment) => currComment.commentID === commentID ) const newLikes = commentToAddLikeTo?.likes if (!commentToAddLikeTo?.likes.includes(userID)) { newLikes?.push(userID) } else { const indexOfUserID = newLikes?.indexOf(userID) newLikes?.splice(indexOfUserID!, 1) } await updateDoc(currentPostRef, { ...currentPost[0], likes: newLikes, })

}

Así es como resolví esto con la ayuda de un compañero de trabajo. Básicamente, estoy manipulando la matriz de Me gusta directamente y luego actualizando toda la información de la publicación.

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!