mongodb - node中往mongo中插入数据的时候,明明插入成功了,但是会返回错误信息?
PHPz
PHPz 2017-05-02 09:22:37
0
1
1102
exports.adduser = function(db) {
    return function(req, res) {
        // Get our form values. These rely on the "name" attributes
        var userName = req.body.username;
        var userEmail = req.body.useremail;
        // Set our collection
        var collection = db.get('users');
        // Submit to the DB
        collection.insert({
            "username": userName,
            "email": userEmail
        }, function(err, doc) {
            if (err) {
                res.send("There was a problem adding the information to the database.");
            } else {
                // If it worked, set the header so the address bar doesn't still say /adduser
                res.location("userlist");
                res.redirect("userlist");
            }
        });
    }
}

插入函数如上,我提交表单之后,查看数据库中是有数据的。但是会打印处if (err)的错误信息?这是什么原因造成的,我如果把res.location("userlist");res.redirect("userlist");移到if err里会报错,不会跳转

PHPz
PHPz

学习是最好的投资!

répondre à tous(1)
小小卫

没豆豆了 打扰了没豆豆了 打扰了没豆豆了 打扰了没豆豆了 打扰了没豆豆了 打扰了没豆豆了 打扰了

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!