0
function SearchUser(searchString) {
MongoClient.connect(url, function (err, db) {
    if (err) throw err;
    db.collection("user").find({ phonenumber: searchString }, function (err, result) {
        if (err) throw err;
        return result;
        db.close();
    });

});

}

I want to get the result back but i only get undefined back.

Pytho
  • 1

1 Answers1

0

It is a scope problem, when you return you return in the scope of the last callback, so you have to return in your main function if you want your result outisde of your function scope

kikiwie
  • 390
  • 1
  • 3
  • 12