title: remove an object from mongodb array of objects
body: <p>I have a problem with removing an object in mongoose.
  I have the schema</p>
  
  <pre><code>shareholder.model.js
  
  const Shareholder = mongoose.Schema({
      name: String,
      shares: [
          {
              type: mongoose.Schema.Types.Mixed, ref: 'shares' 
          }
      ],
  })
  
  mongoose.model('Shareholder', Shareholder)
  </code></pre>
  
  <p>So I'm trying to remove an object from 'shares' field</p>
  
  <pre><code>shareholder.service.js
  
  // {shareholderId} id of object
  // {shareId} unique id which have every object of the array
  
  async function removeShareFromShareholder(shareholderId, shareId) {
  try {
     await Shareholder.findByIdAndUpdate(shareholderId, 
                  { $pull : { 'shares' : { '_id' : shareId } }},
                  { safe: true })
      }
  } catch (error) {
     throw new Error(`removeShareFromShareholder service error: ${error}`)
      }
  }
  </code></pre>
  
  <p>But code above doesn't work</p>
  
  <p>Can you give me an advice</p>