populate 如何与 in populate in mongoDb 一起工作?

how a populate works with-in populate in mongoDb?

我已经为 MongoDB

创建了三个模态框
const mongoose = require('mongoose');
const schema =  mongoose.Schema
const addCategorySchema = schema({
   categoryName:{
       type:String,
       unique:true,
       require:true
   },
   category:{
    type:String,
    default:'compose'
   },
   folder:[{
       type:schema.Types.ObjectId,
       ref:'composeFolder'
   }],
   userId:{
       type:String 
   }
},
{ timestamps:true }
)
module.exports = mongoose.model('compose_category', addCategorySchema)

以上模式适用于类别

const mongoose = require('mongoose');
const schema = mongoose.Schema
const composefolderSchema = schema({
    folderName: {
        type: String,
        unique: true,
        require: true
    },
    template: [{
        type: schema.Types.ObjectId,
        ref: 'sentOrscheduleEmail'
    }],
    userId: {
        type: String
    }
},
    { timestamps: true }
)
module.exports = mongoose.model('composeFolder', composefolderSchema)

以上是分类存放文件夹

const mongoose = require('mongoose');
const schema = mongoose.Schema
const EmailSchema = schema({
   from: {
       type: String,
       require: true
   },
   to: {
       type: Array
   },
   title: {
       type: String,
       require: true
   },
   subject: {
       type: String,
       require: true
   },
   template: {
       type: String
   },    sent_date: {
       type: String,
   },
   sent_time: {
       type: String,
   },

   category: {
       type: String,
       default: ' '
   },
   email_type: {
       type: String,
       default: ' '
   },
   email_status: {
       type: Boolean,
   },
   email_auth_key: {
       type: String,
       require: true
   },
   userId: {
       type: String,
       require: true
   },
   folderId: {
       type: String,
       require: true
   },
   createdBy: {
       type: String
   },
   adminId: {
       type: String
   },
   templete_Id: {
       type: String
   },
   is_Favorite: {
       type: Boolean,
       default: false
   },
   is_Sent: {
       type: Boolean,
       default: false
   },
   attachments: {
       type: Array
   },
   days: {
       type: String
   },
   smartLists: {
       type: Array
   }
},
   { timestamps: true }
)

module.exports = mongoose.model('sentOrscheduleEmail', EmailSchema)

最后一个用于将所有邮件存储在文件夹中 所以我使用 mongoose 创建了所有这三个模型。 我知道填充在 mongoDb 中是如何工作的 例如

db
.find()
.populate({
path:<relational key name>
})

这就是 populate 的工作原理,我的问题是我有三个模型,我想在这三个模型之间使用 populate in mongoDb

建立关系

你可以深入填充。

示例。

<Model>.find().populate({ path: 'path', populate: { path: 'path in path 1' })

您也可以填充多个。

例子

<Model>.find().populate({ path: 'path'}).populate({ path: 'path2' })