ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## **2、Mongoose populate 官方文档** https://mongoosejs.com/docs/populate.html ## **2、Mongoose populate 关联查询** ![](https://box.kancloud.cn/c2f16b67f2055d2dcbf3ebb4244cc82f_1188x471.png) #### 1、定义 ref ``` var ArticleSchema = new Schema({ title:{ type: String, unique: true }, cid : { type: Schema.Types.ObjectId, ref:'ArticleCate' //model 的名称 }, /*分类 id*/ author_id:{ type: Schema.Types.ObjectId, ref:'User' }, /*用户的 id*/ author_name:{ type:String }, descripton:String, content : String }); ``` #### 2、关联查询 ``` ArticleModel.find({}).populate('cid').populate('author\_id').exec(function(err,docs){ console.log(docs) }) ```