这个函数应该返回一个具有给定id的文档:
function detailed(code,callback){
MongoClient.connectAsync(murl).then(function(db) {
return db.collection('reports').find({'_id':code});
}).then(function(reports) {
callback(null, reports)
}).catch(function(err) {
callback(err, null);
});
}
答案 0 :(得分:0)
我想这不是一个mongo相关的问题。 我想你刚刚错过了详细功能的退货声明。
试
function detailed(code,callback){
return MongoClient.connectAsync(murl).then(function(db){
return db.collection('reports').find({'_id':code});
}).then(function(reports) {
callback(null, reports)
}).catch(function(err) {
callback(err, null);
});
}
答案 1 :(得分:0)
当您在蓝鸟中promisifyAll
时,您需要将Async
作为后缀添加到所有方法调用中。您正在调用不是蓝鸟方法的find
- 使用.findAsync
。
此外,如果您需要使用回调,请不要使用.then(...).catch(...)
使用asCallback(callback)