title: Filtering an array field in AWS DocumentDB
body: <p>I am trying to filter the comments field of the post data from my <code>DocumentDB</code>. Here is the structure of the data</p>
  
  <pre><code>{
      _id: &lt;objectidgoeshere&gt;,
      author: {
          userId: 2,
          handleName: "VladimirPutin"
      }
      postBody: "Lorem ipsum dolor amet",
      comments: [
          {
              commentBody: "Another lorem ipsum",
              author: {
                  user_id: 4,
                  handleName: "JohnDoe"
              }
              replies: [
                  {
                      replyBody: "Reply lorem ipsum",
                      author: {
                          user_id: 1,
                          handleName: "JaneDoe"
                      }
                  }
              ]
          },
          {
              commentBody: "Another lorem ipsum 2",
              author: {
                  user_id: 3,
                  handleName: "MarkZucc"
              }
              replies: [
                  {
                      replyBody: "Reply lorem ipsum",
                      author: {
                          user_id: 4,
                          handleName: "JohnDoe"
                      }
                  }
              ]
          }
      ]
  }
  </code></pre>
  
  <p>And suppose the friend and blocked ids are in an array</p>
  
  <p><code>blocked_ids = [4, 5]</code></p>
  
  <p><code>friend_ids = [2, 3]</code></p>
  
  <p>I would like to filter the comments so it will not return the comments of users that are blocked.</p>
  
  <p>My current code looks like this</p>
  
  <pre><code>query = [
      {"$match": {"author.userId": {"$in": friend_ids}}},
      {"$project": {
          "postBody": 1,
          "comments": {
              "$filter": {
                  "input": "$comments",
                  "as": "comments",
                  "cond": {"$nin": ["$$comments.author.user_id", blocked_ids]}
              }
          }
      }
  ]
  </code></pre>
  
  <p>Somehow this query returns the posts from my friends but the comments field is empty.
  I also need to filter the inner array <code>replies</code>. I need to filter out the replies made by users I have blocked.</p>