Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Why not add a list of allowed users to each file system object</p> <p>Adding permissions for a user is easy</p> <pre><code>db.collection.update({folderOrFileNameAndLocation : 'products'}, {$push: {allowedUsers: 'Joe'}}) </code></pre> <p>Removing users is easy</p> <pre><code>db.collection.update({folderOrFileNameAndLocation : 'products'}, {$pull: {allowedUsers: 'Joe'}}) </code></pre> <p>Checking permissions is easy</p> <pre><code>db.collection.find({folderOrFileNameAndLocation : 'products', allowedUsers : 'Joe'}) </code></pre> <p>And listing everything accessible to the user is easy</p> <pre><code>db.collection.find({allowedUsers: 'Joe'}, {folderOrFileNameAndLocation: 1, _id: 0}) </code></pre> <p>One thing that you might find helpful is to build out your files and folders as a tree as opposed to having the location be a string. So you'll have</p> <pre><code>$collection-&gt;insert(array( '_id' =&gt; new MongoID(), 'type' =&gt; 'folder', 'folderOrFileName' =&gt; 'products' )); </code></pre> <p>Then to create a subfolder:</p> <pre><code>$collection-&gt;find(array('folderOrFileName' =&gt; 'products')); $collection-&gt;insert(array( '_id' =&gt; new MongoID(), 'type' =&gt; 'folder', 'folderOrFileName' =&gt; 'device', 'parent' =&gt; $collection['_id'] )); </code></pre> <p>There are pluses and minuses to that structure; depending on what else you need to support you might find your way or the tree way easier. But I would definitely recommend assigning user names to folders instead of vice versa.</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