Mongoose/MongoDB result fields appear undefined in Javascript

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

    If you only want to get the info without all mongoose benefits, save i.e., you can use .lean() in your query. It will get your info quicker and you'll can use it as an object directly.

    https://mongoosejs.com/docs/api.html#query_Query-lean

    As says in docs, this is the best to read-only scenarios.

提交回复
热议问题