# Collection

In this guide, we'll go through the steps to create a new collection in your SoapJS project. You can create collections using CLI commands, interactive forms, or by defining them in a JSON file.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
export class CustomerMongoCollection extends MongoCollection<CustomerMongoModel> {
  constructor(client: MongoSource) {
    super(client, 'customers.collection');
  }
  // additional methods...
}
```

{% endtab %}
{% endtabs %}

## Creating new collection

### Using CLI Command with options

To create a new collection directly via the CLI, use the following command:

```bash
soap new collection -n "Customer" -e "shop" -t "customers.collection" -m "Customer" -s "mongo" -w -f
```

Options explained:

* `-n`: Name of the collection (e.g., "Customer").
* `-e`: Endpoint associated with the collection (e.g., "shop").
* `-t`: Name the table for the collection source.
* `-m`: Name the model associated with the collection. If not set uses collection name.
* `-s`: Storage type(s) (e.g., mongo), separated by commas.
* `-w`: Generate with dependencies included.
* `-f`: Force the creation, overwrite files if necessary.
* `--help`: display help for command

### Using Interactive Form

If you prefer to use an interactive form to specify your collection details, simply run:

```bash
soap new collection -w -f
```

Follow the prompts to enter your collection's details.

### Using JSON Configuration

Alternatively, you can define your collections in a JSON file. Here is an example structure:

```json
{
  "collections": [
    {
      "name": "Customer",
      "endpoint": "shop",
      "types": ["mongo"],
      "model": "Customer",
      "table": "customers.collection"
    }
  ]
}
```

Remember that the model name should be the same as the base collection name. In this case, the model value is unnecessary. The data is provided here only as an example. Save this to a file, for example `api.json`, and run:

```bash
soap new --json "./path/to/api.json" -w -f
```

Options:

* `--json`: Path to your JSON configuration file.
* `--no-tests`: Skip test generation.
* `--no-rel`: Skip generating related files. You can also specify specific groups.
* `--force`: Force the creation, overwrite files if necessary.
* `--patch`: Add content to the files if they exists.

## File Structure

After creating your collection, your file structure (assuming default configuration settings) should look like this:

```
src/
  - shop/
    - data/
      - dtos/
        - customer.dtos.ts
        - index.ts
      - collections/
        - customer.mongo.collection.ts
        - index.ts
...
```
