Skip to main content

Update role

Modifies the data of an existing role

Function UpdateRole(Val Connection, Val Name, Val Base = Undefined, Val PrivilegesArray = Undefined, Val RoleArray = Undefined, Val Parameters = Undefined) Export

ParameterCLI optionTypeRequiredDescription
Connection--dbcString, ArbitraryConnection or connection string
Name--nameStringRole name
Base--dbStringDatabase name. Current database if not specified
PrivilegesArray--prvlArray of StructureArray of privileges. See GetRolePrivilegeStructure
RoleArray--rolesArray Of ArbitraryArray of roles based on strings or structures specifying the database
Parameters--paramsStructure Of KeyAndValueAdditional deletion parameters
Returns

Map Of KeyAndValue - Operation result

tip

The passed roles and privileges completely replace the current role data

Role can be defined in one of the following formats:
Structure: { role: "name", db: "database" }
String: role name


1C:Enterprise/OneScript code example
Address = "127.0.0.1:1234";
Login = "bayselonarrend";
Password = "12we...";
Base = "admin";

ConnectionParams = New Structure("authSource", "admin");
ConnectionString = OPI_MongoDB.GenerateConnectionString(Address, , Login, Password, ConnectionParams);
Connection = OPI_MongoDB.CreateConnection(ConnectionString);

RoleArray = New Array;
RoleArray.Add("read");
RoleArray.Add("userAdmin");

Resource = New Structure("db,collection", Base, "new_collection2");
Actions = New Array;

Actions.Add("find");
Actions.Add("insert");

Privilege = OPI_MongoDB.GetRolePrivilegeStructure(Resource, Actions);

PrivilegesArray = New Array;
PrivilegesArray.Add(Privilege);

RoleName = "newrole";

Result = OPI_MongoDB.UpdateRole(Connection, RoleName, Base, PrivilegesArray, RoleArray);
# JSON data can also be passed as a path to a .json file

oint mongodb UpdateRole \
--dbc "mongodb://bayselonarrend:12we3456!2154@127.0.0.1:27017/?authSource=admin" \
--name "newrole" \
--db "admin" \
--prvl "[{'resource':{'db':'admin','collection':'new_collection2'},'actions':['find','insert']}]" \
--roles "['read','userAdmin']"
Result
{
"result": true,
"data": {
"ok": 1
}
}