title: mongoose - querying for array value in subdocument
body: <p>I am using mongoose. I have the following documents in my database:</p>
  <pre><code>question: {
      &quot;id&quot;: &quot;1&quot;,
          &quot;answers&quot;: [
          {
              &quot;id&quot;: &quot;11&quot;,
              &quot;deletedAt&quot;: &quot;2021-05-28T20:23:30.409Z&quot;,
          }
      }
  },
  question: {
      &quot;id&quot;: &quot;2&quot;,
          &quot;answers&quot;: [
           {
              &quot;id&quot;: &quot;22&quot;,
              &quot;deletedAt&quot;: null,
          }
      }
  }
  </code></pre>
  <p>I am trying to construct a query, which returns all the anwsers, which have a deletedAt value, so are not null.
  I tried the following:</p>
  <pre><code>Question.find({ &quot;answers.deletedAt&quot;: { $ne: null }});
  </code></pre>
  <p>This returns all Questions. However, I would not just like to return only the answers, but just the onces which have a value in the deletedAt field.<br>
  So sticking to the example above, I would like this output:</p>
  <pre><code>{
      &quot;id&quot;: &quot;11&quot;,
      &quot;deletedAt&quot;: &quot;2021-05-28T20:23:30.409Z&quot;,
  }
  </code></pre>
  <p>I would be very thankful for any kind of help!</p>