title: How to compare two arrays and get matching output?
body: <p>In my collection I have a <code>category</code> array as below.</p>
  <p><a href="https://i.stack.imgur.com/SKy1p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SKy1p.png" alt="enter image description here" /></a></p>
  <p>I receive another array to my API like below</p>
  <pre><code>array = ['Chess','Rugby'];
  </code></pre>
  <p>I want to add a condition to my database query such that <code>catName</code> field from <code>category</code> objects exists in <code>array</code>.</p>
  <p>currently I'm using the below code to get the results:</p>
  <pre><code>postSchemaModel.aggregate([{
              &quot;$geoNear&quot;: {
                  &quot;near&quot;: { &quot;type&quot;: &quot;Point&quot;, &quot;coordinates&quot;: [parseFloat(long), parseFloat(lat), ] },
                  &quot;distanceField&quot;: &quot;dist.calculated&quot;,
                  &quot;maxDistance&quot;: parseInt(maxDistance),
                  &quot;includeLocs&quot;: &quot;dist.location&quot;,
                  &quot;spherical&quot;: true
              }
          },
          { &quot;$match&quot;: { &quot;$or&quot;: [{ &quot;typology&quot;: &quot;post&quot; }, { &quot;typology&quot;: &quot;chat_group&quot; }] } },
          {
              &quot;$match&quot;: {
                  &quot;createdAt&quot;: {
                      &quot;$gte&quot;: '2020-07-15 23:54:38.673665',
                      &quot;$lt&quot;: '2020-06-15 23:54:38.673665'
                  }
              }
          },
          { &quot;$limit&quot;: limit },
          { &quot;$skip&quot;: startIndex },
          { &quot;$sort&quot;: { &quot;createdAt&quot;: -1 } },
          {
              &quot;$lookup&quot;: {
                  &quot;from&quot;: userSchemaModel.collection.name,
                  &quot;localField&quot;: &quot;user_id&quot;,
                  &quot;foreignField&quot;: &quot;_id&quot;,
                  &quot;as&quot;: &quot;user_id&quot;
              }
          },
          {
              &quot;$project&quot;: {
                  &quot;post_data&quot;: 1,
                  &quot;likes&quot;: 1,
                  &quot;commentsCount&quot;: 1,
                  &quot;post_img&quot;: 1,
                  &quot;isUserLiked&quot;: 1,
                  &quot;usersLiked&quot;: 1,
                  'exp_date': 1,
                  &quot;has_img&quot;: 1,
                  &quot;user_id&quot;: {
                      &quot;img&quot;: &quot;$user_id.img&quot;,
                      &quot;_id&quot;: &quot;$user_id._id&quot;,
                      &quot;user_name&quot;: &quot;$user_id.user_name&quot;,
                      &quot;bday&quot;: &quot;$user_id.bday&quot;,
                      &quot;imagesource&quot;: &quot;$user_id.imagesource&quot;,
                      &quot;fb_url&quot;: &quot;$user_id.fb_url&quot;,
                  },
                  &quot;typology&quot;: 1,
                  &quot;geometry&quot;: 1,
                  &quot;category&quot;: 1,
                  &quot;created&quot;: 1,
                  &quot;createdAt&quot;: 1,
                  &quot;updatedAt&quot;: 1,
              }
          },
      ]).then(async function(posts) {
          //some code here
          }
      });
  </code></pre>
  <blockquote>
  <p><em>UPDATE : Sample Output</em></p>
  </blockquote>
  <pre><code>{
              &quot;_id&quot;: &quot;5f0bd1b7d6ed4f0017e5177c&quot;,
              &quot;post_data&quot;: &quot;bitch boy sudesh&quot;,
              &quot;likes&quot;: 2,
              &quot;commentsCount&quot;: 1,
              &quot;post_img&quot;: null,
              &quot;isUserLiked&quot;: true,
              &quot;usersLiked&quot;: [
                  &quot;5f0bfa296ee76f0017f13787&quot;,
                  &quot;5ef60bba10e9090017e2c935&quot;
              ],
              &quot;exp_date&quot;: &quot;2020-07-16T00:00:00.000Z&quot;,
              &quot;has_img&quot;: false,
              &quot;user_id&quot;: [
                  {
                      &quot;img&quot;: [
                          &quot;default-user-profile-image.png&quot;
                      ],
                      &quot;_id&quot;: [
                          &quot;5ef9a7a2922eba0017ce47e0&quot;
                      ],
                      &quot;user_name&quot;: [
                          &quot;Sudesh&quot;
                      ],
                      &quot;bday&quot;: [
                          &quot;1997-05-02T00:00:00.000Z&quot;
                      ],
                      &quot;imagesource&quot;: [
                          &quot;fb&quot;
                      ],
                      &quot;fb_url&quot;: [
                          &quot;https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=1846836948784193&amp;width=400&amp;ext=1596011605&amp;hash=AeRsB0QJQH7edpRT&quot;
                      ]
                  }
              ],
              &quot;typology&quot;: &quot;post&quot;,
              &quot;geometry&quot;: {
                  &quot;pintype&quot;: &quot;Point&quot;,
                  &quot;_id&quot;: &quot;5f0bd1b7d6ed4f0017e5177d&quot;,
                  &quot;coordinates&quot;: [
                      79.9200017,
                      6.7088167
                  ]
              },
              &quot;category&quot;: [
                  {
                      &quot;_id&quot;: &quot;5f0bd1b7d6ed4f0017e5177e&quot;,
                      &quot;catID&quot;: &quot;5eef80cc5de48230887f3aa8&quot;,
                      &quot;catName&quot;: &quot;Chess&quot;
                  },
                  {
                      &quot;_id&quot;: &quot;5f0bd1b7d6ed4f0017e5177e&quot;,
                      &quot;catID&quot;: &quot;5eef80cc5de48230887f3aa8&quot;,
                      &quot;catName&quot;: &quot;Rugby&quot;
                  }
              ],
              &quot;created&quot;: 1594610103626,
              &quot;createdAt&quot;: &quot;2020-07-13T03:15:03.629Z&quot;,
              &quot;updatedAt&quot;: &quot;2020-07-18T14:02:35.080Z&quot;
          }
  </code></pre>