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

前端 未结 3 2005
情话喂你
情话喂你 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 13:48

    Try

    schema.virtual('password').get(function () {
        return this.username;
    });
    

    as your getter function, this is your entity instance and the value parameter doesn't mean much here.

    If you were writing a setter function, you would have to write this.username = value.

提交回复
热议问题