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);
})
版权声明:本文为qq_38744335原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。