title: Problem in deleting object using Node.JS, Mongoose, MongoDB, and Express
body: <p>I have a collection called subcategories, another collection called categories
  the collection <strong>categories</strong> has a field called <strong>subcategroies</strong>.
  It's an array that has the ids of the subcategories from the subcategories collections..</p>
  <p>I have an endpoint <strong>DELETE /categories/categoryId/subcategoires/subcategoryId</strong></p>
  <pre><code>subcategories.delete('/:categoryId/subcategories/:subcategoryId', async (req, res) =&gt; {
    try {
      const category = await Category.findById(req.params.categoryId);
      if(!category) return res.status(404).send(&quot;Cateory is not found&quot;);
      category.subCategories.remove( req.params.subcategoryId );
      const subCategory = await SubCategory.findByIdAndRemove(req.params.subcategoryId);
      if(!subCategory) return res.status(404).send(&quot;Subcategory is not found&quot;);
      res.status(202).send(&quot;Subcategory is deleted successfully&quot;);
    } catch (error) {
      res.send(error.message);
    }
  }
  </code></pre>
  <p>So I want to remove the id of the deleted subcategory from the array of subcategories in category model..</p>
  <pre><code>category.subCategories.remove( req.params.subcategoryId );
  </code></pre>
  <p>I tried this line of code as found above but it's not working using <strong>Mongoose</strong>, <strong>MongoDB</strong>, and <strong>Express</strong>.</p>