I am able to connect to mongodb through my nodejs api but for some reason data is not returned. When i query mongodb from console , here is what i get :
MongoDB Enterprise > db.patients.find();
{ "_id" : ObjectId("58c9a5dd1eb8c7c1c68778ca"), "FName" : "n", "LName" : "ri", "Email" : "abc@yahoo.com", "phone" : "1234567890" }
here is the code from nodejs:
app.get('/api/patients',function(req,res){
Patient.getPatients(function(err,patients){
if(err){
throw err;
}
console.log(patients.length);
res.json(patients);
});
});
and this is getPatients method:
var Patient = module.exports = mongoose.model('patient',patientSchema);
// get patients
module.exports.getPatients = function(callback,limit){
Patient.find(callback);
}
But the browser always shows "[]" and no data. When i look at length of array ( console.log(patients.length)) in API , i get 0. Not sure why data is not returned. Can someone pls point me what may be the issue ?
via DevHelp
No comments:
Post a Comment