---
title: "What is Smuggler"
url: "https://docs.ravendb.net/6.2/client-api/smuggler/what-is-smuggler"
version: "6.2"
language: "java"
---

# What is Smuggler

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/client-api/smuggler/what-is-smuggler.md), [Node.js](https://docs.ravendb.net/6.2/client-api/smuggler/what-is-smuggler.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - **Smuggler** is a tool for moving data between databases.  
>   Use it to export documents, indexes, and other items from a database as JSON,  
>   and to import that data into another database.
>
> - Smuggler is exposed through the `DocumentStore.smuggler()` method.
>
> - An export can write to a `.ravendbdump` file or stream directly into another database.  
>   An import reads that data back into a database.
>
> - You can narrow what is transferred by collection, by item type,  
>   and by applying a transform script to each document.
>
> - In this article:
>   - [ForDatabase](#fordatabase)
>   - [Export](#export)
>     - [Export specific collections](#export-specific-collections)
>   - [Import](#import)
>     - [Import specific collections](#import-specific-collections)
>   - [TransformScript](#transformscript)
>   - [Syntax](#syntax)
>     - [Methods](#methods)
>     - [Classes](#classes)

## ForDatabase {#fordatabase}

By default, the smuggler works on the database set in the `DocumentStore.getDatabase()` property.  
To run the smuggler against a different database, switch to it with the `forDatabase` method.

```java
DatabaseSmuggler northwindSmuggler = store
    .smuggler()
    .forDatabase("Northwind");
```

## Export {#export}

Export writes the selected data to a `.ravendbdump` file, or streams it directly into another database.  
Use `DatabaseSmugglerExportOptions` to choose what to include.

#### Example: export indexes and documents to a file

```java
// export only Indexes and Documents to a given file
DatabaseSmugglerExportOptions options = new DatabaseSmugglerExportOptions();
options.setOperateOnTypes(EnumSet.of(
    DatabaseItemType.INDEXES,
    DatabaseItemType.DOCUMENTS));

Operation exportOperation = store
    .smuggler()
    .exportAsync(options, "C:\\ravendb-exports\\Northwind.ravendbdump");

exportOperation.waitForCompletion();
```

### Export specific collections

By default, all collections are exported.  
To export only specific collections, list their names in the `collections` option.

```java
// Export only the "Orders" and "Categories" collections to a file
DatabaseSmugglerExportOptions options = new DatabaseSmugglerExportOptions();
options.setCollections(Arrays.asList("Orders", "Categories"));

Operation exportOperation = store
    .smuggler()
    .exportAsync(options, "C:\\ravendb-exports\\Northwind.ravendbdump");

exportOperation.waitForCompletion();
```

See [exportAsync](#methods) and [DatabaseSmugglerExportOptions](#databasesmugglerexportoptions) in the [Syntax](#syntax) section.

## Import {#import}

Import reads data from a `.ravendbdump` file or a stream and writes it into the database.  
Use `DatabaseSmugglerImportOptions` to choose what to include.

#### Example: import documents from a file

```java
// import only Documents from a given file
DatabaseSmugglerImportOptions options = new DatabaseSmugglerImportOptions();
options.setOperateOnTypes(EnumSet.of(DatabaseItemType.DOCUMENTS));

// import the .ravendbdump file that you exported (i.e. in the export example above)
Operation importOperation = store
    .smuggler()
    .importAsync(options, "C:\\ravendb-exports\\Northwind.ravendbdump");

importOperation.waitForCompletion();
```

### Import specific collections

By default, all collections are imported.  
To import only specific collections, list their names in the `collections` option.

```java
// Import only the "Orders" and "Categories" collections from the file
DatabaseSmugglerImportOptions options = new DatabaseSmugglerImportOptions();
options.setCollections(Arrays.asList("Orders", "Categories"));

Operation importOperation = store
    .smuggler()
    .importAsync(options, "C:\\ravendb-exports\\Northwind.ravendbdump");

importOperation.waitForCompletion();
```

See [importAsync](#methods) and [DatabaseSmugglerImportOptions](#databasesmugglerimportoptions) in the [Syntax](#syntax) section.

## TransformScript {#transformscript}

`TransformScript` lets you modify or filter out each document during an export or import, using JavaScript that you provide.

The JavaScript engine is the same one used for [patching operations](https://docs.ravendb.net/6.2/client-api/operations/patching/single-document.java.md), so you have identical syntax and capabilities, plus the ability to filter out a document by throwing a `skip` exception.

```javascript
var id = this['@metadata']['@id'];
if (id === 'orders/999-A')
    throw 'skip'; // filter-out

this.Freight = 15.3;
```

## Syntax {#syntax}

### Methods

#### Smuggler methods

##### forDatabase

Switches the smuggler to operate on a database other than the document store's default database.

```java
public DatabaseSmuggler forDatabase(String databaseName);
```

Usage:

```java
DatabaseSmuggler northwindSmuggler = store.smuggler().forDatabase("Northwind");
```

| Parameter | Type | Description |
| - | - | - |
| **databaseName** | `String` | The database that the smuggler will operate on. |

| Return value | |
| - | - |
| `DatabaseSmuggler` | A smuggler instance scoped to the specified database. |

##### exportAsync

Exports the selected data to a file or to another database.

```java
public Operation exportAsync(DatabaseSmugglerExportOptions options, String toFile);

public Operation exportAsync(DatabaseSmugglerExportOptions options, DatabaseSmuggler toDatabase);
```

Usage:

```java
Operation exportOperation = store.smuggler().exportAsync(options, toFile);
```

| Parameter | Type | Description |
| - | - | - |
| **options** | `DatabaseSmugglerExportOptions` | Options used during the export. See [DatabaseSmugglerExportOptions](#databasesmugglerexportoptions). |
| **toFile** | `String` | Path to the file where exported data is written. |
| **toDatabase** | `DatabaseSmuggler` | A `DatabaseSmuggler` instance used as the destination. |

| Return value | |
| - | - |
| `Operation` | An `Operation` instance you can use to wait for completion and subscribe to progress events. |

##### importAsync

Imports data from a file or a stream into the database.

```java
public Operation importAsync(DatabaseSmugglerImportOptions options, String fromFile);

public Operation importAsync(DatabaseSmugglerImportOptions options, InputStream stream);
```

Usage:

```java
Operation importOperation = store.smuggler().importAsync(options, fromFile);
```

| Parameter | Type | Description |
| - | - | - |
| **options** | `DatabaseSmugglerImportOptions` | Options used during the import. See [DatabaseSmugglerImportOptions](#databasesmugglerimportoptions). |
| **fromFile** | `String` | Path to the file the data is imported from. |
| **stream** | `InputStream` | Stream with the data to import. |

| Return value | |
| - | - |
| `Operation` | An `Operation` instance you can use to wait for completion and subscribe to progress events. |

### Classes

#### Smuggler options classes

##### DatabaseSmugglerExportOptions

**Options that control what an export includes.**

| Property | Type | Description |
| - | - | - |
| **collections** | `List<String>` | List of specific collections to export. If empty, all collections are exported. <br /> Default: `empty` |
| **operateOnTypes** | `DatabaseItemType` | Indicates what should be exported. <br /> Default: `INDEXES`, `DOCUMENTS`, `REVISION_DOCUMENTS`, `CONFLICTS`, `DATABASE_RECORD`, `IDENTITIES`, `COMPARE_EXCHANGE`, `SUBSCRIPTIONS` |
| **operateOnDatabaseRecordType** | `DatabaseRecordItemType` | Indicates what should be exported from the database record. <br /> Default: `CLIENT`, `CONFLICT_SOLVER_CONFIG`, `EXPIRATION`, `EXTERNAL_REPLICATIONS`, `PERIODIC_BACKUPS`, `RAVEN_CONNECTION_STRINGS`, `RAVEN_ETLS`, `REVISIONS`, `SQL_CONNECTION_STRINGS`, `SORTERS`, `SQL_ETLS`, `HUB_PULL_REPLICATIONS`, `SINK_PULL_REPLICATIONS` |
| **includeExpired** | `boolean` | Should expired documents be exported. <br /> Default: `true` |
| **removeAnalyzers** | `boolean` | Should analyzers be removed from indexes. <br /> Default: `false` |
| **transformScript** | `String` | JavaScript applied to every exported document. See [TransformScript](#transformscript). |
| **maxStepsForTransformScript** | `int` | Maximum number of steps the transform script can run before failing. <br /> Default: `10000` |

##### DatabaseSmugglerImportOptions

**Options that control what an import includes.**

| Property | Type | Description |
| - | - | - |
| **collections** | `List<String>` | List of specific collections to import. If empty, all collections are imported. <br /> Default: `empty` |
| **operateOnTypes** | `DatabaseItemType` | Indicates what should be imported. <br /> Default: `INDEXES`, `DOCUMENTS`, `REVISION_DOCUMENTS`, `CONFLICTS`, `DATABASE_RECORD`, `IDENTITIES`, `COMPARE_EXCHANGE`, `SUBSCRIPTIONS` |
| **operateOnDatabaseRecordType** | `DatabaseRecordItemType` | Indicates what should be imported into the database record. <br /> Default: `CLIENT`, `CONFLICT_SOLVER_CONFIG`, `EXPIRATION`, `EXTERNAL_REPLICATIONS`, `PERIODIC_BACKUPS`, `RAVEN_CONNECTION_STRINGS`, `RAVEN_ETLS`, `REVISIONS`, `SQL_CONNECTION_STRINGS`, `SORTERS`, `SQL_ETLS`, `HUB_PULL_REPLICATIONS`, `SINK_PULL_REPLICATIONS` |
| **includeExpired** | `boolean` | Should expired documents be imported. <br /> Default: `true` |
| **removeAnalyzers** | `boolean` | Should analyzers be removed from indexes. <br /> Default: `false` |
| **transformScript** | `String` | JavaScript applied to every imported document. See [TransformScript](#transformscript). |
| **maxStepsForTransformScript** | `int` | Maximum number of steps the transform script can run before failing. <br /> Default: `10000` |

## See also

- [Backup Task](https://docs.ravendb.net/6.2/studio/database/tasks/backup-task.md)
