> For the complete documentation index, see [llms.txt](https://peakdb.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://peakdb.gitbook.io/docs/constructors/collection.md).

# Collection

The data is stored in collections, where how the collection is created and its detailed information are specified.

### `new Collection(options)`

Create a collection where you can manage and store your data.

| Parameter                               | Default | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| --------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| options                                 |         | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a><br>Collection options.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| options.name                            |         | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>Name of collection.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| options.type                            |         | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>\[IMPORTANT] Type of the collection, which cannot be changed again later.<br><br>Valid values: <code>DOCUMENT\_BASED</code>, <code>KEY\_VALUE\_BASED</code></p>                                                                                                                                                                                                                                                                                                                                                                          |
| options.id\_length                      | `32`    | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a> (optional) <strong>\[DOCUMENT-BASED COLLECTIONS]</strong><br>This determines the length of unique identities given to documents.</p>                                                                                                                                                                                                                                                                                                                                                                                                        |
| options.indicate\_created\_at           | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional) <strong>\[DOCUMENT-BASED COLLECTIONS]</strong><br>Whether to specify the creation date of documents.</p>                                                                                                                                                                                                                                                                                                                                                                                                                       |
| options.indicate\_created\_timestamp    | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional) <strong>\[DOCUMENT-BASED COLLECTIONS]</strong><br>Whether to specify the creation timestamp of documents.</p>                                                                                                                                                                                                                                                                                                                                                                                                                  |
| options.indicate\_edited\_at            | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional) <strong>\[DOCUMENT-BASED COLLECTIONS]</strong><br>Whether to specify the edited date of documents.</p>                                                                                                                                                                                                                                                                                                                                                                                                                         |
| options.indicate\_edited\_timestamp     | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional) <strong>\[DOCUMENT-BASED COLLECTIONS]</strong><br>Whether to specify the edited timestamp of documents.</p>                                                                                                                                                                                                                                                                                                                                                                                                                    |
| options.indicate\_archived\_at          | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional) <strong>\[DOCUMENT-BASED COLLECTIONS]</strong><br>Whether to specify the archived at of documents.</p>                                                                                                                                                                                                                                                                                                                                                                                                                         |
| options.indicate\_archived\_timestamp   | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional) <strong>\[DOCUMENT-BASED COLLECTIONS]</strong><br>Whether to specify the archived timestamp of documents.</p>                                                                                                                                                                                                                                                                                                                                                                                                                  |
| options.indicate\_unarchived\_at        | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional) <strong>\[DOCUMENT-BASED COLLECTIONS]</strong><br>Whether to specify the unarchived at of documents.</p>                                                                                                                                                                                                                                                                                                                                                                                                                       |
| options.indicate\_unarchived\_timestamp | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional) <strong>\[DOCUMENT-BASED COLLECTIONS]</strong><br>Whether to specify the unarchived timestamp of documents.</p>                                                                                                                                                                                                                                                                                                                                                                                                                |
| options.save\_timeout                   | `1`     | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a> (optional)<br>This specifies how many seconds after a document is inserted, the collection will be saved. This way it limits the successive saving of the collection when many data are inserted in succession, so the system is not slowed down. Data loss may occur if the system is turned off after repeatedly entering data. When the document is added 5 times in a row, the collection is saved so that the data does not remain unsaved for a long time. This can be edited with the <code>save\_directly\_after</code> option.</p> |
| options.save\_directly\_after           | `5`     | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a> (optional)<br>This specifies that after how many documents have been inserted, the collection will be saved without the save timeout.</p>                                                                                                                                                                                                                                                                                                                                                                                                   |
| options.cache\_retention\_time          | `10`    | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a> (optional)<br>\[If this value is <code>-1</code>, the cache is kept indefinitely] This specifies how many minutes the cache will be retained if caching is enabled. If there is no activity in the collection, the cache is cleared, thus preventing RAM loss.</p>                                                                                                                                                                                                                                                                          |
| options.backup\_retention\_time         | `3`     | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a> (optional)<br>\[If this value is <code>-1</code>, backups will never be deleted] This determines after how many days the backups will be deleted.</p>                                                                                                                                                                                                                                                                                                                                                                                       |
| options.caching                         | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional)<br>\[IMPORTANT] If this is enabled, the data is kept in the cache. In this case, the data is processed quickly, but the size of the collection is the loss of RAM. Is not preferred for large collections.</p>                                                                                                                                                                                                                                                                                                                 |
| options.auto\_create\_backup            | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional)<br>If this is enabled, this collection will create automatic backups.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| options.detailed\_debugger\_logs        | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional)<br>If this is enabled, it will print more events in the collection to the console.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| options.activate\_drop\_method          | `false` | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional)<br>\[IMPORTANT] If this is enabled, the <code>\<Collection>.Drop()</code> method becomes operable. This command serves to drop your collection completely. It is a dangerous method.</p>                                                                                                                                                                                                                                                                                                                                       |

> Example:
>
> ```javascript
> const example_collection = new <PeakDB | Connection>.Collection({
>   "name": "EXAMPLE_COLLECTION",
>   "type": "DOCUMENT_BASED",
>   
>   /*
>     For document based collections
>   */
>   "id_length": 32,
>   "indicate_created_at": false,
>   "indicate_created_timestamp": true,
>   "indicate_updated_at": false,
>   "indicate_updated_timestamp": true,
>   "indicate_archived_at": false,
>   "indicate_archived_timestamp": true,
>   "indicate_unarchived_at": false,
>   "indicate_unarchived_timestamp": true,
>   
>   /*
>     Can be used on all collection types
>   */
>   "save_timeout": 1,
>   "save_directly_after": 5,
>   "cache_retention_time": 10,
>   "backup_retention_time": 3,
>   "caching": true,
>   "auto_create_backup": true,
>   "detailed_debugger_logs": true,
>   "activate_drop_method": false
> });
> ```
