Create user
Creates a new user
Function CreateUser(Val Connection, Val Name, Val UserRoles, Val Base = Undefined, Val Password = Undefined, Val Parameters = Undefined) Export
| Parameter | CLI option | Type | Required | Description |
|---|---|---|---|---|
| Connection | --dbc | String, Arbitrary | ✔ | Connection or connection string |
| Name | --name | String | ✔ | Users name |
| UserRoles | --roles | Array Of Arbitrary | ✔ | Array of roles as strings or structures specifying the DB |
| Base | --db | String | ✖ | Database name. Current database if not specified |
| Password | --pwd | String | ✖ | Users password |
| Parameters | --params | Structure Of KeyAndValue | ✖ | Additional creation parameters |
Returns: Map Of KeyAndValue - Operation result
tip
Role can be defined in one of the following formats:
Structure: { role: "name", db: "database" }
String: name рoлand
1C:Enterprise/OneScript code example
Address = "127.0.0.1:1234";
Login = "bayselonarrend";
Password = "12we...";
Base = "main";
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");
UserName = "newuser";
UserPassword = "1234";
Result = OPI_MongoDB.CreateUser(Connection, UserName, RoleArray, Base, UserPassword);
- Bash
- CMD/Bat
oint mongodb CreateUser \
--dbc "mongodb://bayselonarrend:12we3456!2154@127.0.0.1:27017/?authSource=admin" \
--name "newuser" \
--roles "['read','userAdmin']" \
--db "main" \
--pwd "1234"
oint mongodb CreateUser ^
--dbc "mongodb://bayselonarrend:12we3456!2154@127.0.0.1:27017/?authSource=admin" ^
--name "newuser" ^
--roles "['read','userAdmin']" ^
--db "main" ^
--pwd "1234"
Result
{
"result": true,
"data": {
"ok": 1
}
}