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
请大家帮忙看一下是怎么回事,谢谢大家!

阅读 3.6k
1 个回答
return yield UserModel.find({name: 'test'}).exec();
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题