BUPT-HJM / vue-blog

A single-user blog built with vue2, koa2 and mongodb which supports Server-Side Rendering
https://imhjm.com
MIT License
598 stars 127 forks source link

请教一个mongoose的问题 #3

Closed ToPeas closed 7 years ago

ToPeas commented 7 years ago

直接贴代码

/server/controllers/articles_controller.js

```js
  let createResult = await article.save().catch(err => {
    ctx.throw(500, '服务器内部错误')
  });
  await Article.populate(createResult, { path: 'tags' }, function(err, result) {
    createResult = result;
    // console.log(result)

  });

查阅了许久的文档,也也看到这个pupulate可以这样使用,直接传入一个model的实例?请问这个是怎么处理的?

BUPT-HJM commented 7 years ago

http://mongoosejs.com/docs/api.html#model_Model.populate 注意这个是Model.populate(),你查文档估计看成Document.populate 其实这里作用就是为了填充tags而已,传入一个document 具体你可以看文档