0

I am trying to migrate my DB from mysql to mongoDB and need some clarifications. First of all the reason for migrating from mysql to mongodb is because of my data structure. In my application i have got users with folders, each user has a root folder and the root folder can contain other folders and files. In my relational db design i have been using parent_id for the folder which is a foreign key to the id of the same table so it acts like a tree, so a folder has childs and a root.

So far this is the perfect example for using embedding, so a user document embeds a folder document('root folder') and from there other folders can contain folders and files for arbitrary depth. see the image below to get an idea about the structure.

enter image description here

However there is a requirement within the application which states that a folder can be 'shared' between many users. Now things get complicated here, because 'sharing' is a many-to-many relationship and this basically contradicts the use of embedding. The last option is to use mongodb's referencing which leads to a design similar to what i was doing in mysql (parent & child..)

First, is there a way to utilize the document based structure of mongodb since my design is similar to tree based document? The only thing which breaks this design is the 'sharing' functionality (many-to-many) and last, what do i gain if i use referencing which is final option instead of mysql since at the end of the day i will need the same amount of queries to retrieve the data?

Comments are appreciated.

Community
  • 1
  • 1
iNDicator
  • 534
  • 2
  • 6
  • 15
  • Mysql solution: If interested there is this answer of mine [Junction Tables](http://stackoverflow.com/a/32620163) . The spot where it has `grade` or `attendance` in the junction table, well yours would either have an effective rights bitmask or various dedicated columns like `canRead` , `canDelete` `canThis`, `canThat`. A junction between users and destinations. Note that users could include groups of users. So, if you want to **stay** in the mysql flock, I would recommend that. If you need assistance with self-joins or hierarchical stuff, perhaps there is something to improve there. – Drew Aug 07 '16 at 16:29
  • Dreq, I have actually implemented the many to many relationship in my relational db using the pivot table etc... my question is whether or not to migrate to db given the info provided for my db design. – iNDicator Aug 07 '16 at 17:57
  • I am just offering an alternative idea. Many will follow and they outnumber us :p – Drew Aug 07 '16 at 17:58
  • Thanks for your suggestion though:) – iNDicator Aug 07 '16 at 18:00

0 Answers0