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

# What is Smuggler

> Client language: Node.js. Also available for [C#](https://docs.ravendb.net/6.2/client-api/smuggler/what-is-smuggler.md), [Java](https://docs.ravendb.net/6.2/client-api/smuggler/what-is-smuggler.java.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` property.
>
> - An export can write to a `.ravendbdump` file.  
>   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.database` property.  
To run the smuggler against a different database, switch to it with the `forDatabase` method.

```javascript
const northwindSmuggler = store
    .smuggler
    .forDatabase("Northwind");
```

## Export {#export}

Export writes the selected data to a `.ravendbdump` file.  
Use `DatabaseSmugglerExportOptions` to choose what to include.

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

```javascript
// export only Indexes and Documents to a given file
const options = new DatabaseSmugglerExportOptions();
options.operateOnTypes = ["Indexes", "Documents"];

const operation = await store
    .smuggler
    .export(options, "C:\\ravendb-exports\\Northwind.ravendbdump");

await operation.waitForCompletion();
```

### Export specific collections

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

```javascript
// Export only the "Orders" and "Categories" collections to a file
const options = new DatabaseSmugglerExportOptions();
options.collections = ["Orders", "Categories"];

const operation = await store
    .smuggler
    .export(options, "C:\\ravendb-exports\\Northwind.ravendbdump");

await operation.waitForCompletion();
```

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

## Import {#import}

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

#### Example: import documents from a file

```javascript
// import only Documents from a given file
const options = new DatabaseSmugglerImportOptions();
options.operateOnTypes = ["Documents"];

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

await operation.waitForCompletion();
```

### Import specific collections

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

```javascript
// Import only the "Orders" and "Categories" collections from the file
const options = new DatabaseSmugglerImportOptions();
options.collections = ["Orders", "Categories"];

const operation = await store
    .smuggler
    .import(options, "C:\\ravendb-exports\\Northwind.ravendbdump");

await operation.waitForCompletion();
```

See [import](#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.nodejs.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.

```typescript
forDatabase(databaseName: string): DatabaseSmuggler;
```

Usage:

```javascript
const 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. |

##### export

Exports the selected data to a file.

```typescript
export(options: DatabaseSmugglerExportOptions, toFile: string): Promise<OperationCompletionAwaiter>;
```

Usage:

```javascript
const operation = await store.smuggler.export(options, toFile);
await operation.waitForCompletion();
```

| Parameter | Type | Description |
| - | - | - |
| **options** | `DatabaseSmugglerExportOptions` | Options used during the export. See [DatabaseSmugglerExportOptions](#databasesmugglerexportoptions). |
| **toFile** | `string` | Path to the file where exported data is written. |

| Return value | |
| - | - |
| `Promise<OperationCompletionAwaiter>` | An awaiter you can use to wait for the operation to complete and subscribe to progress events. |

##### import

Imports data from a file into the database.

```typescript
import(options: DatabaseSmugglerImportOptions, fromFile: string): Promise<OperationCompletionAwaiter>;
```

Usage:

```javascript
const operation = await store.smuggler.import(options, fromFile);
await operation.waitForCompletion();
```

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

| Return value | |
| - | - |
| `Promise<OperationCompletionAwaiter>` | An awaiter you can use to wait for the operation to complete and subscribe to progress events. |

### Classes

#### Smuggler options classes

##### DatabaseSmugglerExportOptions

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

| Property | Type | Description |
| - | - | - |
| **collections** | `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`, `RevisionDocuments`, `Conflicts`, `DatabaseRecord`, `Identities`, `CompareExchange`, `Subscriptions` |
| **operateOnDatabaseRecordType** | `DatabaseRecordItemType[]` | Indicates what should be exported from the database record. <br /> Default: `Client`, `ConflictSolverConfig`, `Expiration`, `ExternalReplications`, `PeriodicBackups`, `RavenConnectionStrings`, `RavenEtls`, `Revisions`, `SqlConnectionStrings`, `Sorters`, `SqlEtls`, `HubPullReplications`, `SinkPullReplications` |
| **includeExpired** | `boolean` | Should expired documents be exported. <br /> Default: `true` |
| **includeArtificial** | `boolean` | Should artificial documents be exported. <br /> Default: `false` |
| **removeAnalyzers** | `boolean` | Should analyzers be removed from indexes. <br /> Default: `false` |
| **transformScript** | `string` | JavaScript applied to every exported document. See [TransformScript](#transformscript). |
| **maxStepsForTransformScript** | `number` | 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** | `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`, `RevisionDocuments`, `Conflicts`, `DatabaseRecord`, `Identities`, `CompareExchange`, `Subscriptions` |
| **operateOnDatabaseRecordType** | `DatabaseRecordItemType[]` | Indicates what should be imported into the database record. <br /> Default: `Client`, `ConflictSolverConfig`, `Expiration`, `ExternalReplications`, `PeriodicBackups`, `RavenConnectionStrings`, `RavenEtls`, `Revisions`, `SqlConnectionStrings`, `Sorters`, `SqlEtls`, `HubPullReplications`, `SinkPullReplications` |
| **includeExpired** | `boolean` | Should expired documents be imported. <br /> Default: `true` |
| **includeArtificial** | `boolean` | Should artificial documents be imported. <br /> Default: `false` |
| **removeAnalyzers** | `boolean` | Should analyzers be removed from indexes. <br /> Default: `false` |
| **transformScript** | `string` | JavaScript applied to every imported document. See [TransformScript](#transformscript). |
| **maxStepsForTransformScript** | `number` | 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)
