Hary
Hary

Reputation: 5818

db.createRole with Mongoose

As per documentation of Mongoose, there is no way to create a role with MongoDB.

I want to perform role creation with MongoDB

db.createRole()

Though, I could see some external libraries doing a similar approach but not exactly the same as above and also some of those are not maintained

mongoose-authorization

mongoose-permission

mongoose-role

Any best approach for this?

Upvotes: 1

Views: 170

Answers (1)

Rajat Masih
Rajat Masih

Reputation: 583

In node js you can achieve it like this

await db.command({
         createRole: 'newTestRole', 
         privileges: [
             { resource: { role: "read",  db: 'dbname', collection: "my_collection" }, actions: ["find"] }
        ],
         roles: []
     });

Upvotes: 1

Related Questions