I have a function in nodejs, whose instructions must be executed sequentially. I've tried the native options (async and await) for node 8 and promises. I can not make him wait for FindOne results before returning.
module.existe = function(usr, pass) {
(async() => {
await coleccion.findOne(
{ usr: usr, pass: pass },
(err, result) => {
return (result == null)? false : true;
}
);
})();
}
the query to mongo is fine, I can recover the document, but always after returning, so the validation does not work. what this function should do is check if a set {usr, key} already exists in the database
What can be?