I am working with mongoose.
I wrote the following code in routes.js
var docs = require('../app/controllers/genericController');
app.post('/newdoc', docs.createMainDoc);
app.get('/listdoc', docs.listDocs);
and in genericController :
exports.listDoc = function(req, res) {
var Model = mongoose.model(req.model); //i dont know, if this is defined or undefined. Actually i am not able to check it. Even if i ment whole body of this exports.listDoc, then also i get the same error. just assume here that here i am getting model.
Model.find(function(err, models) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(models);
}
});
};
Bu i am getting error :
.get() requires callback functions but got a [object Undefined]
How to resolve it?
I am working with mongoose.
I wrote the following code in routes.js
var docs = require('../app/controllers/genericController');
app.post('/newdoc', docs.createMainDoc);
app.get('/listdoc', docs.listDocs);
and in genericController :
exports.listDoc = function(req, res) {
var Model = mongoose.model(req.model); //i dont know, if this is defined or undefined. Actually i am not able to check it. Even if i ment whole body of this exports.listDoc, then also i get the same error. just assume here that here i am getting model.
Model.find(function(err, models) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(models);
}
});
};
Bu i am getting error :
.get() requires callback functions but got a [object Undefined]
How to resolve it?
Share Improve this question asked Sep 4, 2013 at 14:06 codeofnodecodeofnode 18.6k29 gold badges88 silver badges146 bronze badges 1-
Means that
docs.listDocs
is undefined... – epascarello Commented Sep 4, 2013 at 14:10
1 Answer
Reset to default 16You have docs.listDocs
instead of docs.listDoc
. That's why it's undefined
.
app.get('/listdoc', docs.listDoc/*s*/);