title: How to get common attributes from object array in mongodb
body: <p>Below is the sample document</p>
  <pre><code>[
    {
      &quot;name&quot;: &quot;john&quot;
      &quot;attribute&quot;:[
          {
              nameAttr: &quot;abc&quot;
              tagAttr: &quot;zxs&quot;
              
          },
          {
              nameAttr: &quot;asd&quot;
              tagAttr: &quot;zxs&quot;
              
          },
          {
              nameAttr: &quot;lll&quot;
              tagAttr: &quot;zxs&quot;
              
          },
          ]
    },
    {
      &quot;name&quot;: &quot;john&quot;
      &quot;attribute&quot;:[
          {
              nameAttr: &quot;abc&quot;
              tagAttr: &quot;zxs&quot;
              
          },
          {
              nameAttr: &quot;sss&quot;
              tagAttr: &quot;zxs&quot;
              
          },
          {
              nameAttr: &quot;asd&quot;
              tagAttr: &quot;zxs&quot;
              
          },
          ]
    },
  ]
  </code></pre>
  <p>I want to get all common nameAttr output as [&quot;abc&quot;,&quot;asd&quot;] as they are common in both document
  I am able to project only nameAttr with project but dont know how to proceed further
  db.collection.aggregate([</p>
  <pre><code>{
      $project: {
        &quot;attribute.nameAttr&quot;: 1,
        
      }
    }
  ])
  </code></pre>