title: MongoDB structure: single collection vs multiple smaller collections
body: <p>I have a general database structure question.  In my scenario I happen to be using mongodb.</p>
  
  <p>I'm creating an application where a user can upload a list of songs (title, artist, etc.) but am not sure if I should have one songList collection for all users or a separate songList.user# collection for each individual user.  The users can only ever query songs associated to them so user A will NEVER know about user B's songs.</p>
  
  <p><strong>Code Examples:</strong></p>
  
  <p><em><strong>Multiple collections per user</em></strong></p>
  
  <pre><code>db.songList.userA.find()
  {"title": "Some song of user A", "artist": "Some artist of user A"}
  
  db.songList.userB.find()
  {"title": "Some song of user B", "artist": "Some artist of user B"}
  </code></pre>
  
  <ul>
  <li>Pros
  <ul>
  <li>Smaller collection size to query</li>
  </ul></li>
  <li>Cons
  <ul>
  <li>Maintainability 
  <ul>
  <li>1,000 users means 1,000 collections</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p><em><strong>vs single collection with an owning 'user' field</em></strong></p>
  
  <pre><code>db.songList.find({"user":"A"})
  {"title": "Some song of user A", "artist": "Some artist of user A", "user": "A"}
  </code></pre>
  
  <ul>
  <li>Pros
  <ul>
  <li>Flexibility to query across users if need ever arised</li>
  </ul></li>
  <li>Cons
  <ul>
  <li>Performance</li>
  </ul></li>
  </ul>
  
  <p>I'm trying to build a pro/con list but still on the fence.  Given that each user's songs are going to be isolated from each other which approach is better?  My main concern is maintenance and query performance.</p>
  
  <p>Thanks in advance.</p>