首页 > co结合mongoose异步查询返回结果始终为undefined?

co结合mongoose异步查询返回结果始终为undefined?

使用mongoose回调方式能够正确返回结果

UserModel.find({name: 'test'},function(err, data) {
  console.log(data);
});

使用co获取的结果始终为undefined

co(function*() {
    yield UserModel.find({name: 'test'}).exec();
}).then(function (users) {
    console.log(users);
}, function (err) {
    console.error(err);
});

环境为node v4.1.0 , co v4.6.0 , mongoose v4.1.7
请大家帮忙看一下是怎么回事,谢谢大家!


return yield UserModel.find({name: 'test'}).exec();
【热门文章】
【热门文章】