title: Mongodb common key
body: <p>I have a collection</p>
  <pre><code> [{
   name: xyz
  firstname : abc 
  lastname: ghs
  country : india 
  },
   {
    name : fggh
    firstname :bqjdjbw
    lastname :jhhfjk
   }]
  </code></pre>
  <p>Like this array of docs in mongo db, now i need to find a common key in order to optimise my queries right now if i need to find first name and last name i query like this</p>
  <pre><code>   db.getCollection(&quot;db&quot;).find({
    $or: [{name : &quot;xyz&quot; , country:&quot;india&quot;},{name : &quot;cvnb&quot; , 
     country:&quot;india&quot;},]},
     {&quot;first name&quot;:1,
     &quot;lastname&quot;:1,
     &quot;_id&quot;:0 })
  </code></pre>
  <p>Can someone help me how can i find a common key or can i find id or use some algorithm to optimise it since i will eventually have to add in my java code.</p>