检查 findOne mongodb nodejs 的结果

check the result of findOne mongodb nodejs

mongo.connect(url, {useNewUrlParser: true}, function(error, db) {
    if (error) throw error;
    var dbo = db.db("mydb");
    console.log("connected to databse successfully");
    dbo.collection("users").findOne({}, {"email": email}) (function(err, result) {
        if (!result) {
            res.sendfile(__dirname + '/register.html');
        } else {
            dbo.collection("users").insertOne(data, function(err, collection){
                if (err) throw err;
                console.log("Record inserted successfully");
                console.log(collection);
                res.status(200).send('You are loged in, Welcome!');
            });
        }
    });
});

我想查看结果。如果邮件已经在数据库中,我不会将其添加到记录中。但是不行

您的 findOne 查询是 incorrect.

dbo.collection("users").findOne({}, {"email": email}) (function(err, result){

应该

dbo.collection("users").findOne({"email": email}) (function(err, result) {