I follow a MCV approach to develop my application. I encounter a problem that I dont know how the arguments are passed to the callback function.
animal.js (model)
var mongoose = require('mongoose')
, Schema = mongoose.Schema
var animalSchema = new Schema({ name: String, type: String });
animalSchema.statics = {
list: function(cb) {
this.find().exec(cb)
}
}
mongoose.model('Animal', animalSchema)
animals.js (controller)
var mongoose = require('mongoose')
, Animal = mongoose.model('Animal')
exports.index = function(req, res) {
Animal.list(function(err, animals) {
if (err) return res.render('500')
console.log(animals)
}
}
Here comes my question: Why can the "list" in the model just execute callback without passing any argument? Where do the err and animals come from actually?
I think I may miss some concepts related to callback in node.js and mongoose. Thanks a lot if you can provide some explanation or point me to some materials.