> This page location: /docs.md > /docs/development.md > /docs/manual/reference/command.md

> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# compactStructuredEncryptionData (database command)

## Definition

Compacts documents specified in the metadata collections and deletes redundant documents.

## Compatibility

This command is available in deployments hosted in the following environments:

- [MongoDB Atlas](https://www.mongodb.com/docs/atlas): The fully managed service for MongoDB deployments in the cloud

**Note:**

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see [Unsupported Commands.](https://www.mongodb.com/docs/atlas/unsupported-commands/)

- [MongoDB Enterprise](https://www.mongodb.com/docs/manual/administration/install-enterprise.md#std-label-install-mdb-enterprise): The subscription-based, self-managed version of MongoDB

- [MongoDB Community](https://www.mongodb.com/docs/manual/administration/install-community.md#std-label-install-mdb-community-edition): The source-available, free-to-use, and self-managed version of MongoDB

## Syntax

The command has the following syntax:

```javascript
db.runCommand(
  {
    compactStructuredEncryptionData: <collection>,
    compactionTokens: {
       encryptedFieldPath: bindata,
       ...
    },
  }
)
```

## Command Fields

The command takes the following fields:

| Field | Type | Description |
| --- | --- | --- |
| `compactStructuredEncryptionData` | string | The name of the collection. |
| `compactionTokens` | document | A document that maps index fields to compaction tokens. |

The [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) provides a wrapper method [`db.collection.compactStructuredEncryptionData()`.](https://www.mongodb.com/docs/manual/reference/method/db.collection.compactstructuredencryptiondata.md#mongodb-method-db.collection.compactStructuredEncryptionData)

## Required Access

The built-in roles [`readWriteAnyDatabase`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-authrole-readWriteAnyDatabase) and [`dbOwner`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-authrole-dbOwner) provide [`compactStructuredEncryptionData`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-compactStructuredEncryptionData) actions on resources.

## Example

See [metadata collection compaction](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/manage-collections.md#std-label-qe-metadata-compaction) for an example.
