title: many to many relationship with nosql (mongodb and mongoose)
body: <p>I'm doing a relationship with many to many with mongoDb and mongoose.js, i know that there is many options, my situation is this:</p>
  
  <p>I've two documents, user and projects, one user can have many projects and one project can have many user, so in my case i've 4 options:</p>
  
  <blockquote>
    <p>1 - An array of id_user inside project document.</p>
    
    <p>2 - An array of id_project inside user document.</p>
    
    <p>3 - An array of id_user inside project document &amp;&amp; An array of
    id_project inside user document.</p>
    
    <p>4 - A third table mapping user and project relationship(like a
    relational database).</p>
  </blockquote>
  
  <p>The option 1 and 2 are unavailable, because, imagine in the scenario of the option 1 if i wanted to find all projects from the user, i will have to look for this user id inside every project document array of the users(traverse this array in every project), this definitely  isn't a good approach.</p>
  
  <p>The option 3 is good but i will have to make some kind of transaction to ensure that both documents will be written, it's not that bad, because both documents will be much more read than written</p>
  
  <p>The option 4 is simpler because when i add one user to a project, it's just to add a new document with both id's(it's good solution i think, because i will don't need to care about transaction, it's a good solution?)</p>
  
  <p>So, what's the best solution?</p>