Learning Activity: Creating New Roles. Yet again

this issue has already been raised here:

this topic is closed already,
but I’m getting the same weird error too though I’m pretty sure that my solution is correct.
Here is my solution:

and here is the output of online IDE:

Am I the idiot here or someone else?

From the first line we see in your terminal, I suspect that the previous command failed with some error. And the output of getRoles() does not seem to match what your createRole() is supposed to do.

It looks like createRole() was called once with wrong parameters and then a second time with the parameters you shared but failed with an error like role already exists.

My suggestion is that you first https://docs.mongodb.com/manual/reference/method/db.dropRole/ the role you created and then redo createRole().

Please post screenshot of both commands.

1 Like

I am stuck at the same point. I tried to drop the the role “insertAndFindTransactions”, system is coming up with false, so tried creating again the role “insertAndFindTransactions”, system is coming up as role already exists. My question is

  1. why below drop role command is giving “false” output? db.dropRole(“insertAndFindTransactions”) and when trying to create this role again coming as role already existing.
  2. In previous lab exercise I already granted roles to “emailsAdmin” with below command:
    db.grantRolesToUser(“emailsAdmin”,[{ role: “dbAdmin”, db: “emails” }])
    then why run test command is failing on this? I again granted these roles, but still the tests are not passing.
    Please help.

1.droprole giving false means role may not be existing
Are you using/querying correct DB?If you don’t switch to admin it will create in test DB
What does db.getRoles() show?

2.Have you given all required roles to emailsAdmin?May be something is missing so your test is failing

Hi Ram,
Thanks for your response. I reset the workspace, refreshed the IDE environment and did the following:

  1. connected as global admin user
  2. changed to admin db
    3.created user emailsAdmin, got response as successfully created user
  3. Added roles dnAdmin to emailsAdmin user on db emails, no response, but just returned prompt “>”
  4. created user “insertAndFindTransactions” with proper syntax and the roles as required in the exercise, no errors reported by system. All these modifications or creations were done after switching to admin db. The command that I use was

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

  1. Run tests failed with same message as the first post of Aug 21.
    7.Below is output of db.getRoles()
    “role” : " insertAndFindTransactions",
    “db” : “admin”,
    “isBuiltin” : false,
    “roles” : [ ],
    “inheritedRoles” : [ ]

Hope I explained clearly what I did,
Can you please guide me what went wrong?
Thank you

Is this dnAdmin or dbAdmin?
How did you name the role while creating?
The test usually fails due to typos in role name/db name or some space gets introduced etc
Check our forum threads.You will get some clues
Is dbadmin sufficient for the user emailsAdmin?
What all he is doing on emails DB?
Check all your steps again


Thank you for your response. The actual command to create emailsAdmin was right, when I typed here it was wrong. I followed your hint about unwanted space and it worked. But as a matter of curiosity:

role: “insertAndFindTransactions”
different from
role: " insertAndFindTransactions"?, there must be a rule of syntax that a role name can not start with a space or a special character.
It never occurred to me that a role name can start with space.
Thanks anyway, I will watch out for any extra space which is good though in these COVID times

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