hi my friend iI use this method to retrieve data from db iI hope that can help
user.find({key: 1})
.then((userOne)=>{
//if is an API
res.status(200).json({data : userOne});
//OR
// if you had a view named profile.ejs for example
res.render('/profile',{data : userOne, title : 'User profile' });
console.log(userOne); // just for check in console
})
.catch((error)=>{
//if an api
res.status(400).json({messageError : error});
// OR
if not an api
res.render('/profile',{data : 'No data of this profile',errorToDisplay : error})
});
});
user.find({key: 1})
.then((userOne)=>{
//if is an API
res.status(200).json({data : userOne});
//OR
// if you had a view named profile.ejs for example
res.render('/profile',{data : userOne, title : 'User profile' });
console.log(userOne); // just for check in console
})
.catch((error)=>{
//if an api
res.status(400).json({messageError : error});
// OR if not an api
res.render('/profile',{data : 'No data of this profile',errorToDisplay : error})
});
});