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

115
Vistas
Get documents name in Firestore and create nested object

This question is related to this one: Get documents names in Firestore but I can't comment yet.

I am trying to get a nested object from my FireStore which looks like this

{"docname1": {…}, "docname2": {…}, "docname3": {…}}

I have this now but cant seem to figure out how to create the nested object to push it into the empty array.

 useEffect(() => {
    const getPlants = async () => {
        let response = []
        const querySnapshot = await firebase
            .firestore()
            .collection('plants')
            .get()
        querySnapshot.forEach((doc) => {
            let newObject = [doc.id: doc.data() ]
            response.push(newObject)
        })

        setPlants(response)
    }
    getPlants()
}, [])

Any help is greatly appreciated :)

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

0

I think you are creating the new object (newObject) wrong. Try to create it like this:

   querySnapshot.forEach((doc) => {
       const newObject = {}
       newObject[doc.id] = doc.data()
       response.push(newObject)
   })

Or, you can do this:

   querySnapshot.forEach((doc) => {
       response.push({ [`${doc.id}`]: doc.data() })
   })
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