---
title: "Compact Collection"
method: PUT
path: "/_fabric/{fabric}/_api/collection/{collection-name}/compact"
tags: ["Administration"]
---

# Compact Collection

`PUT /_fabric/{fabric}/_api/collection/{collection-name}/compact`

## Request

- The document declares no server URL.
- Auth: one of:
  - API key in header `Authorization`
  - HTTP bearer
- TypeScript: <https://skmtc.dev/macrometa/apis/macrometa-api-reference/docs/_fabric/:fabric/_api/collection/:collection-name/compact/put.ts> (a function with typed inputs; its response is checked against the schema)

Compacts the data of a collection in order to reclaim disk space.
 The operation compacts the document and index data by rewriting the data while keeping the relevant entries.
Under normal circumstances running a compact operation is not necessary, as the collection data eventually gets compacted anyway. However, in some situations, e.g. after running many update or remove operations, the data for a collection may contain a lot of outdated data for which the space shall be reclaimed. In this case, the compaction operation can be used.

## Path parameters

- `fabric` string, string, required
- `collection-name` string, string, required

## Response `200`

Successfully compacted the collection.

- ApiCollectionPutCollectionCompactHttpExampleRc200
  - `code` integer: HTTP response code.
  - `error` boolean: Flag if there is an error in response. *False* for this response.
  - `id` string: Id of the the collection.
  - `name` string: Name of the collection.
  - `status` 0 | 2 | 3 | 4 | 5 | 6: Status of the collection. - *0*: corrupted - *2*: unloaded - *3*: loaded - *4*: unloading - *5*: deleted - *6*: loading
  - `type` 2 | 3: Type of the collection. - *0*: invalid collection - *2*: document collection - *3*: edge collection
  - `collectionModel` 'DOC' | 'KV' | 'DYNAMO': Type of collection model. - *DOC*: document model - *KV*: key/value model - *DYNAMO*: dynamo model
  - `isSpot` boolean: *True* if collection is a spot collection.
  - `isLocal` boolean: *True* if collection is a local collection.
  - `hasStream` boolean: *True* if collection has a stream.
  - `waitForSync` boolean: *True* if all data must be synced to storage before operation returns.
  - `isSystem` boolean: *True* if collection is a system collection.
  - `globallyUniqueId` string: Collection's global unique Id.
  - `searchEnabled` boolean: *True* if collection is searchable.

## Other responses

- `400`: Failed due to missing or malformed data. Verify that all parameters are complete.
- `404`: Failed to find specified collection.

---

[API](https://skmtc.dev/macrometa/apis/macrometa-api-reference.md) - [All operations](https://skmtc.dev/macrometa/apis/macrometa-api-reference/llms.txt) - [OpenAPI document](https://skmtc.dev/macrometa/apis/macrometa-api-reference/revisions/2006b6d7f31d?raw)
