Mongoose returns undefined for an existing field

后端 未结 3 1708
执笔经年
执笔经年 2020-12-06 18:22

After a mongoose request I have my document doc which is the result of the query

Here is the schema used

var searchSchema = new mongoose         


        
相关标签:
3条回答
  • 2020-12-06 19:02

    This is do to the fact that the toString() method of the object returns the _doc property. You can use: console.log(doc._doc.image);

    0 讨论(0)
  • 2020-12-06 19:03

    Try to use the bracket notation like that:

    doc['image']
    

    If it works, I'm not able to explain you why, but maybe someone could shed some light on this?

    0 讨论(0)
  • 2020-12-06 19:21

    You'll see this when you haven't added the field to your schema.

    Add image to your schema and it should work:

    image: String
    
    0 讨论(0)
提交回复
热议问题