有没有一种方法可以在代码中使用node.js错误结果?

I'm trying to make a bot require a user token from a certain database, I am going to try (If possible) to use the console response, So for example, If I get a response saying "Status: Active" it will run the code, But if I get a response with [], Meaning the user is no longer in the database, the code will not run. I'm just trying to figure out if I can call the console response in my code. My current code is:

bot.on("ready", message => {
    let dtoken = config.UserToken
    MongoClient.connect(url, function(err, db) {
        if (err) throw err;
        var dbo = db.db("test");
        var query = { dtoken: dtoken };
        dbo.collection("tokens").find(query).toArray(function(err, result) {
          if (err) throw err;
          console.log(result)
          db.close();
        });
      });
})
评论