title: Mongodb: how to populate a schema referenced in my schema through my api
body: <p>I want to edit my Api to be able to populate a referenced schema.
  here is my schema:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>export const taskSchema = new Schema ({
      user:{
          type: String,
          required: true
      },
      project: { 
          type: String,
          required: true
      },
      issue: {
          type: String,
          required: true
      },
      title: {
          type: String,
          required: true
      },
      records : [{
     
          _domain: {
              type: Schema.Types.ObjectId,
              ref: 'TaskDomains'
          },
          time: {
              type:Number
          }
      
      }],
      
     
      dateCreated: {
       
          type: Date,
          default: Date.now
      }
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>my taskDomain schema :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>export const TaskDomains = new Schema ({
      label:{
          type: String,
          required: true
      }
  
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>how can I edit the following post method to populate the referenced TaskDomain schema.
  here is my method:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import * as mongoose from 'mongoose';
  import {taskSchema,TaskDomains} from '../models/tasks.model';
  import {Request, Response} from 'express';
  
  const Task = mongoose.model('Task', taskSchema);
  const domain = mongoose.model('domain', TaskDomains);
  export class taskController{
  public addNewTask (req: Request, res:Response){
          let newTask = new Task();
          newTask.user = req.body.user;
          newTask.project = req.body.project;
          newTask.issue = req.body.issue;
          newTask.title = req.body.title;
          newTask.dateCreated = req.body.dateCreated;
          newTask.records = new domain(req.body._domain);
          newTask.records = new domain(req.body._domain.label);
          newTask.records = req.body.time;
  
          newTask.save((err, task)=&gt;{
              if(err){
                  res.send(err);
              }
              res.json(task);
          });
      }
      }</code></pre>
  </div>
  </div>
  
  I need help editing the post method. I have been trying different ways but none worked.</p>