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.
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.