Can't access object property, even though it shows up in a console log

后端 未结 30 2282
日久生厌
日久生厌 2020-11-22 06:26

Below, you can see the output from these two logs. The first clearly shows the full object with the property I\'m trying to access, but on the very next line of code, I can\

30条回答
  •  离开以前
    2020-11-22 06:55

    I've just had the same issue with a document loaded from MongoDB using Mongoose.

    Turned out that i'm using the property find() to return just one object, so i changed find() to findOne() and everything worked for me.

    Solution (if you're using Mongoose): Make sure to return one object only, so you can parse its object.id or it will be treated as an array so you need to acces it like that object[0].id.

提交回复
热议问题