title: How to delete subdocument using mongoose?
body: <p>I have a mongoDB with the following schema:</p>
  <pre><code>const jobSchema = new mongoose.Schema({
      companyTitle: String,
      status: String,
      companyURL: String,
      jobTitle: String,
      jobURL: String,
      jobDescription: String,
      contactName: String,
      contactRole: String,
      contactPhone: String,
      contactEmail: String,
      tasks: [Task.schema]
  })
  
   const taskSchema = new mongoose.Schema({
      taskItem: String,
      isCompleted: Boolean
  })
  </code></pre>
  <p>When a user clicks a button, the job._id and task._id are sent to my server where the specific task should be deleted from the database. Currently, the route deletes the parent (job) instead of the child (task). Any ideas how to target the task instead? Thanks in advance!</p>
  <p>app.js</p>
  <pre><code>app.delete('/tasks/:jobId/:taskId', (req, res) =&gt; {
      const jobId = req.params.jobId
      const taskId = req.params.taskId
  
      Job.findOneAndDelete(
          {'_id': jobId, 'tasks._id': taskId},
          function (error, doc) {
              if (error) {
                  console.log(error)
              } else {
                  console.log(doc)
              }
          }
      )
  })
  </code></pre>