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

180
Views
Nodejs | Object property is available but it's returning 'undefined'

I've been trying to solve this for about 2 hours. I am returning an object in Nodejs. This object has 3 properties. I can access the first two, but when I try to access the third property, I get the 'undefined' warning. I'm about to go crazy can you help me please?

Request:

  const categories = await Categories.find({}); //mongoose query
  console.log(categories[0]); //its returning Object
  console.log(categories[0].category); //its returning  []
  console.log(categories[0]._id); //its returning  new ObjectId("6257233b897c3b8785ff625b")
  console.log(categories[0].mainCategories); //its returning  undefined ?? wtf?!
  console.log(categories[0].hasOwnProperty("category")); //its returning false
  console.log(categories[0].hasOwnProperty("_id")); //its returning false
  console.log(categories[0].hasOwnProperty("mainCategories")); //its returning false

Object Result:

{
  category: [],
  _id: new ObjectId("6257233b897c3b8785ff625b"),
  mainCategories: [
    { id: 1000010100, name: 'Konut', subCategories: [Array] },
    { id: 1000010200, name: 'Devremülk', subCategories: [Array] },
    { id: 1000020100, name: 'İşyeri', subCategories: [Array] },
    { id: 1000020200, name: 'Arazi', subCategories: [Array] },
    {
      id: 1000020300,
      name: 'Turistik İşletme',
      subCategories: [Array]
    }
  ]
}

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The answers given by Cristian Traìna and VebDav caused lightning in my brain. I couldn't find the exact solution to the problem on the internet. But different problems guided me. The problem stems from my stupidity. I forgot to enter the mainCategories field in the mongoose category schema. I added this and its fixed. Thank you so much everyone for your answers.

enter image description here

And now its returning mainCategories :)

enter image description here

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!