I want to list all the data from a collection in a database in mongodb:
From the following requests:
http://localhost:3000/listdoc?model=Organization
I am implementing the following code :
exports.listDoc = function(req, res) {
var Model = mongoose.model(req.query.model); //This is defined and returns my desired model name
Model.find().populate('name').exec(function(err, models) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(models);
}
});
};
I already have my entry in the database But the above code returns empty. I don't know why?
The schema:
var Organization = mongoose.Schema({
name: String
});