简体   繁体   English

几次验证后无法将文档保存到 mongoose 集合

[英]Cant save document to mongoose collection after a few validations

I want to save the following object to my mongoose collection:我想将以下 object 保存到我的 mongoose 收藏中:

school = {
    coinPart: ['sd', 'asd'],
    crinPart: ['n', 'n'],
    ppPart: ['n', 'n'],
    quizPart: ['n', 'n'],
    submittedEvents: ['coin'],
    _id: 5f113ade6ee3cb248c6864b4,
    schoolName: 'myschool',
    teacherName: 'myteacher',
    teacherEmail: 'teacher@email.com',
    teacherPhone: '7000000000'
}

and this is how I am doing so:这就是我这样做的方式:

console.log(school);
school.save((err, doc) => {
    if (!err) {
        console.log(err, doc);
        res.redirect(`/register/${doc._id}`);
    } else {
        if (err.name == "ValidationError") {
            handleValidationError(err, req.body);
            res.render("events/addEdit", {
                fields: req.body,
                check: allEvents,
            });
        } else if (err.name == "MongoError" && err.code == 11000) {
            res.render("events/addEdit", {
                oyehoye: "School Already Registered!",
                fields: req.body,
                check: allEvents,
            });
        } else {
            console.log("Error registering school " + err.name);
        }
    }
}

But after 3-4 incorrect submissions (and validating them with mongoose schema), neither do I get an error on the console, nor do I get the doc data, and localhost takes forever to load, I can't understand what I have done wrong, because when I submit the form correctly in 2-3 attempts (validating only 2-3 times), this problem isn't caused and the doc is successfully saved.但是在 3-4 次错误提交后(并使用 mongoose 模式验证它们),我既没有在控制台上收到错误,也没有收到文档数据,并且 localhost 需要永远加载,我无法理解我做了什么错误,因为当我在 2-3 次尝试(仅验证 2-3 次)中正确提交表单时,不会导致此问题并且文档已成功保存。

The problem was due to a connectivity issue, its now fixed该问题是由于连接问题引起的,现已修复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM