---
sidebar_position: 2
description: Create collection 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';

# Create collection
 Creates a new collection with the specified parameters



`Function CreateCollection(Val Connection, Val Name, Val Base = Undefined, Val Parameters = Undefined) Export`

  | Parameter | CLI option | Type | Required | Description |
  |-|-|-|-|-|
  | Connection | --dbc | String, Arbitrary | &#x2714; | Connection or connection string |
  | Name | --name | String | &#x2714; | Collection name |
  | Base | --db | String | &#x2716; | Database name. Current database if not specified |
  | Parameters | --params | Structure Of KeyAndValue | &#x2716; | Additional creation parameters |

  
  Returns:  Map Of KeyAndValue - Operation result



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

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


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