Why are my Mongoose 3.8.7 schema getters and setters being ignored?

前端 未结 3 1989
情话喂你
情话喂你 2021-02-19 13:01

While working with Node.js, Mongoose and MongoDB, I have found that my Mongoose schema getters and setters do not fire when I perform a findOne query.

I have found an ol

3条回答
  •  温柔的废话
    2021-02-19 14:00

    I was having the same problem with getters not modifying the returned documents when querying with Mongoose. To make this apply to every query, you can do this:

    // Enable Mongoose getter functions
    schema.set('toObject', { getters: true });
    schema.set('toJSON', { getters: true });
    

提交回复
热议问题