Is there a way to call function that contains mongoose query inside other function, so other function will work properly?
My first function containing mongoose query:
getUserTags = (id) => {
User.findById(id)
.exec( (error, user) => {
if (error) {
return next(error);
} else {
return user;
}
})
}
and my functions that needs to call that first function:
userTagToBookTagValues = (id) => {
const user = getUserTags(id);
//I NEED THIS PART TO WORK AFTER getting data from getUserTags
console.log(user);
user.tags.forEach(tag => {
console.log(tag)
});
}
Is there a way so it works properly and user in second function will not be undefined?