---
sidebar_position: 2
description: Update role and other functions to work with MongoDB in the Open Integration Package, a free open-source integration library for 1C:Enterprise 8, OneScript and CLI
keywords: [1C, 1С, 1С:Enterprise, 1С:Enterprise 8.3, API, Integration, Services, Exchange, OneScript, CLI, MongoDB]
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# 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`

  | Parameter | CLI option | Type | Required | Description |
  |-|-|-|-|-|
  | Connection | --dbc | String, Arbitrary | &#x2714; | Connection or connection string |
  | Name | --name | String | &#x2714; | Role name |
  | Base | --db | String | &#x2716; | Database name. Current database if not specified |
  | PrivilegesArray | --prvl | Array of Structure | &#x2716; | Array of privileges. See GetRolePrivilegeStructure |
  | RoleArray | --roles | Array Of Arbitrary | &#x2716; | Array of roles based on strings or structures specifying the database |
  | Parameters | --params | Structure Of KeyAndValue | &#x2716; | Additional 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:<br/>Structure: `{ role: "name", db: "database" }`<br/>String: `name рoлand`
:::
<br/>


```bsl title="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);
```
 

 <Tabs>
  
    <TabItem value="bash" label="Bash" default>
        ```bash
            # 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']"
        ```
    </TabItem>
  
    <TabItem value="bat" label="CMD/Bat" default>
        ```batch
            :: 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']"
        ```
    </TabItem>
</Tabs>


```json title="Result"
{
 "result": true,
 "data": {
  "ok": 1
 }
}
```
