Create collection
Creates a new collection with the specified parameters
- Parameters
- Advanced call ?
Function CreateCollection(Val Connection, Val Name, Val Base = Undefined, Val Parameters = Undefined) Export
| Parameter | CLI option | Type | Required | Description |
|---|---|---|---|---|
| Connection | --dbc | String, Arbitrary | ✔ | Connection or connection string |
| Name | --name | String | ✔ | Collection name |
| Base | --db | String | ✖ | Database name. Current database if not specified |
| Parameters | --params | Structure Of KeyAndValue | ✖ | Additional creation parameters |
Returns
Map Of KeyAndValue - Operation result
| Parameter | Description |
|---|---|
| addin_mode | Manual selection of external component connection mode (for 1C): Isolated, NotIsolated |
| dontwait | Creates a background job and returns its data (for 1C and OneScript only) |
1C:Enterprise/OneScript code example
Address = "127.0.0.1:1234";
Login = "bayselonarrend";
Password = "12we...";
ConnectionParams = New Structure("authSource", "admin");
ConnectionString = OPI_MongoDB.GenerateConnectionString(Address, , Login, Password, ConnectionParams);
Connection = OPI_MongoDB.CreateConnection(ConnectionString);
Name = "test_collection";
Base = "test_database";
Parameters = New Map;
Expression = New Map;
GroupAnd = New Array;
Condition1 = New Map; // Total >= 0
Items1 = New Array;
Items1.Add("$total");
Items1.Add(0);
Condition1.Insert("$gte", Items1);
Condition2 = New Map; // Status <= 3
Items2 = New Array;
Items2.Add("$status");
Items2.Add(3);
Condition2.Insert("$lte", Items2);
GroupAnd.Add(Condition1);
GroupAnd.Add(Condition2);
Expression.Insert("$expr", GroupAnd);
Parameters.Insert("validator", Expression);
Result = OPI_MongoDB.CreateCollection(Connection, Name, Base, Parameters);
- Bash
- CMD/Bat
# JSON data can also be passed as a path to a .json file
oint mongodb CreateCollection \
--dbc "mongodb://bayselonarrend:12we3456!2154@127.0.0.1:27017/?authSource=admin" \
--name "test_collection" \
--db "test_database" \
--params "{'validator':{'$expr':[{'$gte':['$total','0']},{'$lte':['$status','3']}]}}"
:: JSON data can also be passed as a path to a .json file
oint mongodb CreateCollection ^
--dbc "mongodb://bayselonarrend:12we3456!2154@127.0.0.1:27017/?authSource=admin" ^
--name "test_collection" ^
--db "test_database" ^
--params "{'validator':{'$expr':[{'$gte':['$total','0']},{'$lte':['$status','3']}]}}"
Result
{
"result": true,
"data": {
"ok": 1
}
}