function _allUsers(callback){
var db = connect.get();
db.collection("users").find({}).toArray(function(err,data){
if(err){
callback(err);
}else{
callback(null,data);
}
});
}
I am trying to understand this code, I have been looking around the web but I find the explanations kinda defficult to understand ( I am new at Mean stack), so my questions are:
-
What does the Collection method do? I am not sure but the string "users" is it just the name of our collection with all users?
-
Why do we have to use a callback in this situation? (I find callbacks very confusing).
-
And why do we have to give toArray function, an annonymous function?
-
Instead of toArray could I use pretty method() without any annonymous function as a parameter?
Aucun commentaire:
Enregistrer un commentaire