Error: "createRole" command requires a "roles" array

Hi all!

I’m getting this error when I want to create a role to do the exercise:
uncaught exception: Error: “createRole” command requires a “roles” array :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createRole@src/mongo/shell/db.js:1675:15
@(shell):1:1

This is my code:

use admin

db.createRole(
 {
   role: "insertAndFindTransactions",
   privileges: [
     {
        resource: { db: "transactions", collection: "" },
        actions: [ "insert", "find" ]
     }
   ]
 }
)

Hi @Zelmar_Michelini,

Welcome to the MongoDB Community forums :sparkles:

I would request you to kindly look at the shared post thread:

I hope it will help you to resolve your problem.

In case you have any doubts, please feel free to reach out to us.

Thanks,
Kushagra Kesav,
Curriculum Services Engineer

Hi Kushagra

It doesn’t help.

I setting the databse name in the resource and check for typo, but still getting the error

best
Zelmar

Hi @Zelmar_Michelini,

You need to add roles: [ ] after the privileges: [ ], in your command.

I hope it will help!

Thanks,
Kushagra

2 Likes

Thanks a lot! That it was I missed

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.