Note that there are some explanatory texts on larger screens.

plurals
  1. POvirtual folders with mongoDB logic
    text
    copied!<p>Need a bit of logic help. I have a folder I'll be uploading alot of files to via http/php/post. I'm going to index them into a collection in MongoDB when they upload. I need to organize the files into different folders, in reality there will be no folders, but when someone will be viewing the interface I'll be putting together it will look like a file tree. I'll also be setting permissions to the virtual folders. I've been thinking over and over of how to index the files into virtual folders into a Mongo Collection, where I get stuck is assigning permissions to each user. I was thinking of indexing a file and virtual folders like this(sorry for the long code, just trying to give you an idea of how deep the file tree will go):</p> <pre><code>$collection-&gt;insert(array( '_id' =&gt; new MongoID(), 'type' =&gt; 'folder', 'folderOrFileNameAndLocation' =&gt; 'products' )); $collection-&gt;insert(array( '_id' =&gt; new MongoID(), 'type' =&gt; 'folder', 'folderOrFileNameAndLocation' =&gt; 'products/device' )); $collection-&gt;insert(array( '_id' =&gt; new MongoID(), 'type' =&gt; 'folder', 'folderOrFileNameAndLocation' =&gt; 'products/device/manuals' )); $collection-&gt;insert(array( '_id' =&gt; new MongoID(), 'type' =&gt; 'file', 'fileName' =&gt; 'theManual.pdf', 'location' =&gt; 'products/device/manuals/' )); </code></pre> <p>My problem is how to assign permissions to folders for each user when I add a user, here's what I was thinking</p> <pre><code>$collection-&gt;insert(array( '_id' =&gt; new MongoID(), 'username' =&gt; 'Joe', 'password' =&gt; '1234', //will obviously be one way hashed //STORE AS A STRING 'permissibleFolders' =&gt; 'products/device/manuals/, software/latest/' )); //OR SHOULD I DO IT THIS WAY??? $collection-&gt;insert(array( '_id' =&gt; new MongoID(), 'username' =&gt; 'Joe', 'password' =&gt; '1234', //will obviously be one way hashed 'permissibleFolders' =&gt; array( //DO I HAVE TO SET A KEY FOR THIS OR CAN I JUST ADD THEM IN? products/device/manuals/, software/latest/ ) )); </code></pre> <p>Now by doing it that way, how would I query the folders allocated to the user? This is what I was thinking, but how do I query the last part? I can make it work with a nested query, but that's something I try to never do.</p> <pre><code>$pulledData = $collection-&gt;find(array('username' =&gt; $username, 'password' =&gt; $password)); $doesExist = $pulledData -&gt; count(); if($doesExist == 1){ logUserInAndStuff(); foreach($pulledData as $row){ $accessibleFolders = $row['permissibleFolders']; } //HOW DO I MAKE THIS QUERY THE PROPER FOLDERS? $pulledData = $collection-&gt;find(array('folderNameAndLocation'=&gt;$accessibleFolders)); } </code></pre> <p>Sorry if my logic is stupid, I just have very limited "pull" with the server and what I'm allowed to do. I was given nothing and expected to pull through with something grand. Any better way of doing this that someone could help me come up with would be awesome! I'm pretty new to noSQL, I maybe thinking too much structure lol.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload