Lab - Creating First Application User - No role named readWrite

I can’t seem to figure out how best to create my user and assign it the appropriate role. No matter the DB I attempt the creating and assignment I receive the following:

Error: couldn’t add user: No role named readWrite@

MongoDB Enterprise > db.createUser(
… { user: “m103-application-user”,
… pwd: " m103-application-pass ",
… roles: [ { db: " applicationData ", role: “readWrite” } ]
… }
… )
2019-05-21T03:32:16.845+0000 E QUERY [thread1] Error: couldn’t add user: No role named readWrite@ applicationData :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell):1:1
MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > db.createUser(
… { user: “m103-application-user”,
… pwd: " m103-application-pass ",
… roles: [ { db: " admin ", role: “readWrite” } ]
… }
… )
2019-05-21T03:34:51.295+0000 E QUERY [thread1] Error: couldn’t add user: No role named readWrite@ admin :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell):1:1

Any thoughts?

1 Like

Hi @Blake_99043,

Here when you are creating user with db.createUser(), make sure that db points to the admin database.
So, use admin database before creating m103-application-user.

Let me know, if you still face any problem.

Thanks,
Sonali

Same issue…

MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > db.createUser(
… { user: “m103-application-user”,
… pwd: “m103-application-pass”,
… roles: [ { db: " admin ", role: “readWrite” } ]
… }
… )
2019-05-21T11:44:37.414+0000 E QUERY [thread1] Error: couldn’t add user: No role named readWrite@ admin :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell):1:1

Issue resolved:

I finally figured out that the query submitted to the DB hates spaces.

Once I removed the spaces the issue resolved itself.

MongoDB Enterprise > db.createUser(
… { user: “m103-application-user”,
… pwd: “m103-application-pass”,
… roles: [ { db: “applicationData”, role: “readWrite” } ]
… }
… )
Successfully added user: {
“user” : “m103-application-user”,
“roles” : [
{
“db” : “applicationData”,
“role” : “readWrite”
}
]
}

@Sonali_Mamgain

1 Like