title: indexing large array in mongoDB
body: <p>according to mongoDB documentation, it's not recommended to create multikey index for large arrays, so what is the alternative option for that?</p>
  
  <p>I want to notify my app users whenever one of their contacts also start using the app, so I have to upload and manage the contacts list of each user.
  we are using mongoDB with replica set of master with two secondaries machines.
  does mongo can handle multikey indexing for array with hundreds of values?
  hundreds of contacts for hundreds thousands of users can be very hard to mange.</p>
  
  <p>the multikey solution looks like that:</p>
  
  <pre><code>{
    customerId: "id1",
    contacts: ["aaa", "aab", "aac", .... "zzz"]
  }
  </code></pre>
  
  <p>index: <code>createIndex({ contacts: 1 })</code>.  </p>
  
  <p>another solution is to save each contacts in it's own document and save all the app users that related to him:  </p>
  
  <pre><code>{
    phone: "aaa",
    contacts: ["id1", "id2", "id3"]
  },
  {
    phone: "aab",
    contacts: ["id1"]
  },
  {
    phone: "aac",
    contacts: ["id1"]
  },
  ......
  {
    phone: "zzz",
    contacts: ["id1"]
  }
  index: createIndex( { phone: 1 } )
  </code></pre>
  
  <p>both have poor performance on writing when uploading the contacts list:<br>
  the first on calculate huge index, and the second for updating lots of documents concurrent.<br>
  Is there a better way to do it?<br>
  I'm using a replica set with two secondaries machines, does shard key could help?  </p>
  
  <p>Thanks</p>