Organizational Research By

Surprising Reserch Topic

many to many relationship with nosql mongodb and mongoose


many to many relationship with nosql mongodb and mongoose  using -'mongodb,nosql,mongoose,nosql-aggregation'

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:

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:


  1 - An array of id_user inside project document.
  
  2 - An array of id_project inside user document.
  
  3 - An array of id_user inside project document && An array of
  id_project inside user document.
  
  4 - A third table mapping user and project relationship(like a
  relational database).


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.

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

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?)

So, what's the best solution?
    
asked Sep 29, 2015 by nimisha.jagtap
0 votes
3 views



Related Hot Questions



Government Jobs Opening


...