3
Я пытаюсь получить JSON из Mongodb с помощью Express.js, и он возвращает «Undefined» в моей консоли. Не могли бы вы посоветовать?Express.js - возвращает объект Mongo Undefined
app.js:
var db = monk('localhost:27017/nodetest1', {
username : 'USERNAME',
password : 'PASSWORD'
});
index.js:
router.get('/url', function(req,res){
var db = req.db;
var collection = db.get('test1');
collection.find({},{},function(e,docs){
console.log(docs) // Returns "Undefined"
res.send(docs);
});
});
Вы можете проверить для неопределенных переменных как описано в http://stackoverflow.com/questions/2647867/how-to-determine-if-variable-is-undefined-or-null –