[DOCS-4132] Comment on: "manual/tutorial/assign-role-to-user.txt" Created: 06/Oct/14  Updated: 03/Nov/17  Resolved: 07/Oct/14

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: Bret Ferrier Assignee: Unassigned
Resolution: Done Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 2012 running the server my machine is windows 8.1. I am accessing mongo via robomongo

Location: http://docs.mongodb.org/manual/tutorial/assign-role-to-user/
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
Referrer: http://docs.mongodb.org/manual/administration/security-user-role-management/
Screen Resolution: 1920 x 1080
repo: docs
source: tutorial/assign-role-to-user


Participants:
Days since reply: 9 years, 19 weeks, 1 day ago

 Description   

I am running mongo 2.6 and when attempting to add a role the command
db.grantRolesToUser threw an error saying that the command did not exist.

I ended up stumbling upon another syntax that actually worked (Makes me think your documentation is out of date) Below worked on mongo 2.6.1

db.runCommand(
{ grantRolesToUser: "remote",
roles: [

{ role: "readWrite", db: "Venue" }

],
writeConcern:

{ w: "majority" , wtimeout: 2000 }

} )



 Comments   
Comment by Kay Kim (Inactive) [ 07/Oct/14 ]

Hi Bret –
the db.grantRolesToUser() method is available in MongoDB 2.6 in the mongo shell. It is a wrapper around the command grantRolesToUser:

function (username, roles, writeConcern) {
    var cmdObj = {grantRolesToUser: username,
                  roles: roles,
                  writeConcern: writeConcern ? writeConcern : _defaultWriteConcern};
    var res = this.runCommand(cmdObj);
    if (!res.ok) {
        throw Error(res.errmsg);
    }

Generated at Thu Feb 08 07:47:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.