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

129
Vistas
cant map array of object query from mangodb

please i am facing map is not a function error when i tried to map array of object from mongodb.

and the console.log returns the correct data but in string format. please help me on how to go about it. thanks

const [printz, setPrintz] = useState([ ])

    const getOrder = async() =>{
        try {
            const res = await axios.get("/products/receipt/all")
            setPrintz(res.data)
        } catch (error) {
            console.log(error);
        }
     }
    
    useEffect(()=>{
        getOrder()
    }, [ getOrder])

    console.log({DbDatas: printz}) // return the correct data


   {printz && printz.map(x =>(                   
        <tbody >
            <tr>
                <td>{x.product}</td>
                <td>{x.price}</td>
            </tr>
            
        </tbody>
    )) }   
    </table>

bellow is the screenshot from the mongodb

mongodb data

...console.log

i think the problem is from the backend

router.get('/receipt/all', async (req, res) => {
    try {
        const getprint = await Prints.find()
        res.status(200).json( getprint +'Succes!')
    } catch (error) {
        res.status(500).json(`Error fetching data!!! ${error}`)
    }
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Currently it's in string format. You should parse it by using JSON.parse(). In this example

JSON.parse(printz).map()
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