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

168
Views
pass data from mongoose to ejs

I have the following model

const userSchema = new mongoose.Schema({
    username: String,
    likes: Number
})

and a route

app.get("/users/:id", async(req, res) => {
    const id = req.params.id
    let cc = await User.find({ username: id });
    let raw = cc;
    res.render('index', {data : raw})

})

when I hit this route it works fine and on the front end, it prints the array that is returned by cc. i.e

[{"_id":"6282d457f697743c1145a02","username":"John","likes":0,"__v":0}]

But, on the HTML side, if I try to access <%= data[0].likes %> I get an undefined error for "likes"

Similarly, when I try to pass a specific property of the object to ejs for example

res.render('index', {data : raw[0].likes}

I get an error that says Cannot read properties of undefined (reading 'likes')

why is this error occurring

over 4 years ago · Santiago Trujillo
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!