node.js - Retrieving data with mongoose -
I am currently trying to get users of Mongoose, but when I move the function to a different module If I try, then it throws something errors that are not very helpful then some introduction:
If I use this in the controller:
export.index2 = function (Req, res) {users.find (function (err, users) {If (err) {console.log ("ERR");} console.log (user); res.json (user);});} ;
Everything is working fine, but when I try to isolate it like this, it does not work.
export.index = function (req, res) {UsersModel.findAll (function (users, err) {if (! Err) {console.log (users); <- - This is not showing res.send (users);} else console.log (err);}); };
// is in the model, which is required in the controller
findAll: function () {User.find (function (mistake, user) { If (err) {console.log ("ERR");} //console.log(users); & lt; --- This Returns Showing User;}); },
I was getting undefined, because I was trying to find not all sync and async. After "taking care", undefined disappeared, but it still does not work.
Comments
Post a Comment