title: MongoDB schema strategy for users joining a group
body: <p>Imagine Facebook's group feature, using MongoDB. What would be the best way to structure the data?</p>
  
  <p>Main operations on this data will be find users who belong to the group and determine if user X is a member of the group.</p>
  
  <p>One option would be to have an array of strings in the <code>Group</code> document.</p>
  
  <pre><code>{
    name: "Pets United",
    members: [
      "iuahsdfuhasdfasdf",
      "qwefqwefqwefqweff",
      "ioeroigkergnknmkm"
    ]
  }
  </code></pre>
  
  <p>Another would be to have a <code>membership</code> array of Group id's in the <code>User</code> document.</p>
  
  <pre><code>{ 
    firstName: "Sergio",
    age: 27,
    groups: [
      "iuahsdfuhasdfasdf",
      "qwefqwefqwefqweff",
      "ioeroigkergnknmkm"
    ]
  }
  </code></pre>
  
  <p>Which one do you guys think is better if I expect a group to have thousands of users?</p>