MongoDB Collection Level Permission Issues I am trying to set up a MongoDB user that only has access to certain collections across several databases.  The issue is that these databases are created dynamically at runtime.
I decided to employ collection level access in order to do this with the following permission on the user role:
&quot;db&quot; : &quot;admin&quot;,
&quot;privileges&quot; : [ 
    {
        &quot;resource &quot; : {
            &quot;cluster&quot; : true
        },
        &quot;actions&quot; : [ 
            &quot;listDatabases&quot;
        ]
    }, 
    {
        &quot;resource&quot; : {
            &quot;db&quot; : &quot;&quot;,
            &quot;collection&quot; : &quot;packages&quot;
        },
        &quot;actions&quot; : [ 
            &quot;find&quot;, 
            &quot;insert&quot;, 
            &quot;remove&quot;, 
            &quot;update&quot;, 
            &quot;listCollections&quot;
        ]
    }]

What I want is for any user with this role to be able to read/write/remove in any database but only on the packages collection inside of that database, and be unable to read or write to any other collection.  When I launch mongod in --auth I do not see any databases besides admin.
I am certain this is just me being unable to figure out exactly what actions / resources / roles I am supposed to grant.
Not clear what you mean but this could be a solution:
var role = &quot;&lt;role name&gt;&quot;; 
admin = db.getSiblingDB(&quot;admin&quot;);
if (admin.getRoles({ rolesInfo: role }).length == 0)
   admin.createRole({ role: role, privileges: [], roles: [] });
admin.grantRolesToUser(&lt;the user&gt;, [role]);
   

Then you would have to run this code every time when a new database is created.
db.getSiblingDB(&lt;your dynamic database name&gt;).getCollectionNames().forEach(function (item) {
   db.getSiblingDB(&quot;admin&quot;).grantPrivilegesToRole(role, [{
      resource: {
         db: &lt;your dynamic database name&gt;, collection: item }, 
         actions: [&quot;find&quot;, &quot;insert&quot;, &quot;remove&quot;, &quot;update&quot;] }])
   })