mongoose 有两种调用方式,1种callbacl,1种promise。
比如定义个getAll
1.callback
a.js
回调形式,外面
function getAll(cb){
xxModel.find({},cb);
}
module.exports.getAll=getAll;
b.js
var a=require('a');
a.getAll(function(err,result){
console.log(result);
})
2.promise
a.js
function personTest() {
return Person.find({}).exec();
}
b.js
var a=requre('a');
a.getAll().then(fnction(rseult){
console.log(result);
}).catch(function(err){
console.log(err);
})