猫鼬不在表中多次推送数据

时间:2019-03-06 07:47:27

标签: node.js mongodb express mongoose

您好,我尝试多次推送数据,但只推送一次。为什么阻止我进一步推进。

我的控制器:-

const mongoose = require ('mongoose');
const crypto = require('crypto');
const nodemailer = require("nodemailer");
const Admin = mongoose.model('Admin');

module.exports.registerAdmin = (req, res, next) =>{ 

    var admin = new Admin();
    admin.email = req.body.email;
    admin.password = req.body.password;
    admin.firstName = req.body.firstName;
    admin.lastName = req.body.lastName;

    //saving users data to database
    admin.save((err) =>{
        if(!err){
            console.log("passed");
        }
        else{
            if (err.code == 11000)
                    res.status(422).send(["Entered duplicate email address. Please check"]);
            else
            return next(err);
            }
    });
}

当我第一次安慰时,它“通过” ,但是第二次显示错误“输入了重复的电子邮件地址。请在控制台中检查”

0 个答案:

没有答案