I've already stablished a DB with it's schema like this:
When I use my search function in Nodejs it works perfectly and returns my info like this:\
So, why is is than when I try to fectch my user from mongodb and get the parameter "examenes":
CodePudding user response:
Have you added mergeParams
in your router?
This options adds params object to the request
const router = express.Router({ mergeParams: true });
then
/predict/:id
results in req.params.id
By default this option is disabled in express
CodePudding user response:
The problem is you are not using await
so in the line console.log(user.examenes)
the variable user
is not the data returned by mongo, is naother object without attribute examenes
. And trying to access the value is undefined
.
So you can use:
let user = await (usuario.findOne({_id: req.params.id}))