I developing an app with tree(folder-file) structure, on which I should perform full-text searches with MongoDB. I did a research on the best tree structure practices and found this great article, but I still can not decide which DB structure will fit my needs.
I have the following requirements in my mind:
- I should be able to perform full-text search on individual folders, as well as everything from specific users
- The folders/files should be shareable, so I need to be able to perform full-text search on all items accessible by specific user
I've been thinking about the following structures.
Fields of Users collection 1. _id - objectid 2. name - string Fields of Folders collection 1. _id - objectid 2. name - string 3. owner - objectid 4. sharedWith - array of objectIds 5. location - objectid of parent folder, null if in root 6. createDate - datetime Fields of File collection 1. _id - objectid 2. name - string 3. owner - objectid 4. sharedWith - array of objectIds 5. data - string 6. location - objectId of folder 7. createDate - datetime
So here comes my questions:
- Should I use model tree structures with Parent References or Child References?
- Should I use 1 collection for both files and folders(with type field) or I should separate them.
- Does it worth to have only folder collection and nest documents in it.
This were my most important questions, thought I will greatly appreciate any advice on how I can improve the structure.