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

# changeStreamOptions

## Definition

**New in version 6.0**

Atlas clusters and self-hosted deployments

An object that contains [change stream](https://www.mongodb.com/docs/manual/changestreams.md#std-label-changeStreams) configuration options.

You can only set `changeStreamOptions` on [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) or a replica set primary. The value is set cluster-wide.

## Syntax

To set `changeStreamOptions` for your deployment, run the following command on the `admin` database:

```javascript
db.adminCommand( { setClusterParameter: { changeStreamOptions: <value> } } )
```

To view current values for the `changeStreamOptions` cluster parameter, run the following command on the `admin` database:

```javascript
db.adminCommand( { getClusterParameter: "changeStreamOptions" } )
```

## Parameter Fields

**New in version 6.0**

*Default*: off

Controls the retention policy of change stream pre- and post-images. Pre- and post-images are the versions of a document before and after document modification respectively. `expireAfterSeconds` controls how long MongoDB retains pre- and post-images.

When `expireAfterSeconds` is `off`, MongoDB uses the default retention policy: pre- and post-images are retained until the corresponding change stream events are removed from the [oplog.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-oplog)

To set the minimum pre- and post-image retention time, specify an integer value for `expireAfterSeconds`.

**Important:**

Services that use change streams, including [Triggers](https://www.mongodb.com/docs/atlas/app-services/triggers/database-triggers/) and [Device Sync](https://www.mongodb.com/docs/atlas/app-services/sync/), might rely on the availability of pre-image data. If you set `expireAfterSeconds` too low, you may increase the risk of interrupting sync or triggers processing.

When setting `expireAfterSeconds` for pre-images, ensure that you:

- Specify a value that isn't lower than the typical change stream lag for the service.

- Add buffer time to allow the service to resume manually before risking oplog data loss.

## Behavior

If a change stream event is removed from the oplog, then the corresponding pre- and post-images are also deleted regardless of the retention time specified with [`changeStreamOptions.preAndPostImages.expireAfterSeconds`.](https://www.mongodb.com/docs/manual/reference/cluster-parameters/changestreamoptions.md#mongodb-parameter-param.changeStreamOptions.preAndPostImages.expireAfterSeconds)

## Example

The following example sets the retention time for pre- and post-images in change streams to `100` seconds:

```javascript
db.runCommand( {
   setClusterParameter: {
      changeStreamOptions: { preAndPostImages: { expireAfterSeconds: 100 } }
   }
} )
```
