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

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

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 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!