Mongoose/MongoDB result fields appear undefined in Javascript

前端 未结 10 2262
囚心锁ツ
囚心锁ツ 2020-11-27 20:13

Is there something that I\'m missing that would allow item to log as an object with a parameter, but when I try to access that parameter, it\'s undefined?

What I\'ve

10条回答
  •  迷失自我
    2020-11-27 20:45

    Use findOne() instead of find().

    The find() method returns an array of values, even if you have only one possible result, you'll need to use item[0] to get it.

    The findOne method returns one object or none, then you'll be able to access its properties with no issues.

提交回复
热议问题