Mongoose/MongoDB result fields appear undefined in Javascript

前端 未结 10 2288
囚心锁ツ
囚心锁ツ 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:51

    Old question, but since I had a problem with this too, I'll answer it.
    This probably happened because you're using find() instead of findOne(). So in the end, you're calling a method for an array of documents instead of a document, resulting in finding an array and not a single document. Using findOne() will let you get access the object normally.

提交回复
热议问题