0

In this little function I validate incoming emails using module "email-check" (it works, so no problems here) and using "count" method in my mongoDB collection. Here is the code:

var emailCheck = require("email-check"),
express = require("express");

var Validate = function (email, dbCollection) {
    emailCheck(email)
        .then(function (res) {
            if (res === true && dbCollection.count({"email": email}) === 0) {
                console.log("Email is OK ");
                dbCollection.insert({"email": email.toLowerCase()});
            }
        })
        .catch(function (err) {
            if (err.message === "refuse") {
                console.log("The MX server is refusing requests from your IP address");
            } else {
                console.log("Unexpected error");
            }
        });
};

module.exports = Validate;

But, I am sure, this fragment does not work: dbCollection.count({"email": email}) === 0

Console shows me that: "Promise ". I cannot get what is wrong here and how can I rewrite this to make everything work. Help me out with this :)

P.S: mongoDB version is 2.2, all code except for bolded one works just fine.

Evgeny Kobzev
  • 89
  • 1
  • 12

0 Answers0