Mongoose post save hook只运行一次

时间:2018-05-02 23:11:53

标签: node.js mongoose

我在Mongoose中有一个post保存挂钩,它在我第一次向路由发送请求时有效。它正确更新了我指定的属性。随后我向邮件发送邮件请求时出现问题。什么都没发生,我可以看到邮递员的请求。关于我可能遗失的任何想法?

代码

let mongoose = require('mongoose');
let Schema = mongoose.Schema;

let SubscriberSchema = new Schema({
    id: {
        type: String,
        required: false
    },
    firstName: {
        type: String,
        required: false
    },
    lastName: {
        type: String,
        required: false
    },
    emailAddress: {
        type: String,
        required: true
    },
    phoneNumber: {
        type: String,
        required: false
    },
    clientId: {
        type: String,
        required: true
    }
});

SubscriberSchema.post('save', (doc) => {
    doc.id = doc._id;
    doc.save();
});

module.exports = mongoose.model('Subscriber', SubscriberSchema);

0 个答案:

没有答案