Skip to main content

Grant roles

Grants selected roles to a user

Function GrantRoles(Val Connection, Val User, Val RoleArray, Val Base = Undefined, Val Parameters = Undefined) Export

ParameterCLI optionTypeRequiredDescription
Connection--dbcString, ArbitraryConnection or connection string
User--userStringUsers name
RoleArray--rolesArray Of ArbitraryRole or role array
Base--dbStringDatabase name. Current database if not specified
Parameters--paramsStructure Of KeyAndValueAdditional deletion parameters
Returns

Map Of KeyAndValue - Operation result

tip

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);

User = "bayselonarrend";
Role = New Structure("role,db", "newrole", Base);

Result = OPI_MongoDB.GrantRoles(Connection, User, Role, Base);
# JSON data can also be passed as a path to a .json file

oint mongodb GrantRoles \
--dbc "mongodb://bayselonarrend:12we3456!2154@127.0.0.1:27017/?authSource=admin" \
--user "bayselonarrend" \
--roles "{'role':'newrole','db':'admin'}" \
--db "admin"
Result
{
"result": true,
"data": {
"ok": 1
}
}