I'm trying use find function to get data from my DB in mLab. I wrote this code, but I am getting an empty string. My schema had id, name, course and grade. It works for me when I want the file of the name but not for id. I guess it's because of the extra _id files that the mLab adds. How do I fix it to get back the JSON that fits the id (let's say id=1)?
app.get('/getStudentById/:id', function(req, res) { //else if url path is getStudGrade with id param
Stud.find({id:req.params.id}, function(err, user){
if(err) throw err;
res.json(user);
mongoose.disconnect();
});
})
new edit
I have changed the filed 'id' to 'idStudent' in my DB and now it working.
Stud.find({ idStudent: req.params.id)}...)
but why?
getStudentById