title: Deleting Subdocument from an array of schema
body: <p>I have a user schema and each user have a profile in which he has a collection of book, and the user wants to remove a single book from the bookCollection, I have tried my code is at the bottom. The user schema is as follows:</p>
  <pre><code>var bookSchema = new Schema({
  title: {
      type: String,
      required: true,
  },
  author: {
      type: String,
      required: true,
  },
  publisher: {
      type: String,
      default: &quot;not set&quot;
  },
  desc: {
      type: String,
      default: &quot;not set&quot;
  },
  availableAs: {
      type: String, //either hardcopy or softcopy
      required: true
  },
  
  price: {
      type: Number,
      default: 0
  },
  category: {
      type: String,
      default: &quot;not set&quot;
  },
  imageurl: {
      type: String,
      default: 'nobook.png'
  
  },
  bookurl: {
      type: String,
      default: ''
  },
  softcopy_available: {
      type: Number,
      default: 0
  }
  });
  
  
  
  
  
  var userSchema = new Schema({
   admin: {
      type: Boolean,
      default: false
   },
   bookCollection: [bookSchema]
  });
  </code></pre>
  <p>This is what I am trying, but deletion is not working, sometimes it shows error and the page keeps on loading.</p>
  <pre><code>router.post('/', (req, res, next) =&gt; {
  console.log(req.body.bookid);
  var id=req.body.bookid;
  
  users.findOne({
  
      })
      .then((user1) =&gt; 
          user1.bookCollection.pull(req.body.bookid._id);
      })
      .catch((err) =&gt; {
          next(err)
  
      });
  });
  </code></pre>