What is Smuggler

Smuggler gives you the ability to export or import data from or to a database using JSON format.
It is exposed via the DocumentStore.smuggler().

ForDatabase

By default, the IDocumentStore.smuggler works on the default document store database from the IDocumentStore.database property.

In order to switch it to a different database use the .forDatabase method.

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

Export

Syntax

//export
public Operation exportAsync(DatabaseSmugglerExportOptions options, String toFile);

public Operation exportAsync(DatabaseSmugglerExportOptions options, DatabaseSmuggler toDatabase);
Parameters
options DatabaseSmugglerExportOptions Options that will be used during the export. Read more here.
toDatabase DatabaseSmuggler DatabaseSmuggler instance used as a destination
toFile String Path to a file where exported data will be written
Return Value
Operation Instance of Operation class which gives you an ability to wait for the operation to complete and subscribe to operation progress events

DatabaseSmugglerExportOptions

Parameters
Collections List<String> List of specific collections to export. If empty, then all collections will be exported. Default: empty
operateOnTypes DatabaseItemType Indicates what should be exported. Default: Indexes, Documents, RevisionDocuments, Conflicts, DatabaseRecord, Identities, CompareExchange, Subscriptions
operateOnDatabaseRecordType DatabaseRecordItemType Indicates what should be exported from database record. Default: Client, ConflictSolverConfig, Expiration, ExternalReplications, PeriodicBackups, RavenConnectionStrings, RavenEtls, Revisions, SqlConnectionStrings, Sorters, SqlEtls, HubPullReplications, SinkPullReplications
includeExpired boolean Should expired documents be included in the export. Default: true
removeAnalyzers boolean Should analyzers be removed from Indexes. Default: false
transformScript String JavaScript-based script applied to every exported document. Read more here.
maxStepsForTransformScript int Maximum number of steps that transform script can process before failing. Default: 10000

Example

// export only Indexes and Documents to a given file
Operation exportOperation = store.smuggler().exportAsync(exportOptions, "C:\\ravendb-exports\\Northwind.ravendbdump");

Import

Syntax

public Operation importAsync(DatabaseSmugglerImportOptions options, String fromFile);
public Operation importAsync(DatabaseSmugglerImportOptions options, InputStream stream);
Parameters
options DatabaseSmugglerImportOptions Options that will be used during the import. Read more here.
stream InputStream Stream with data to import
fromFile String Path to a file from which data will be imported
Return Value
Operation Instance of Operation-class which gives you an ability to wait for the operation to complete and subscribe to operation progress events

DatabaseSmugglerImportOptions

Parameters
Collections List<String> List of specific collections to import. If empty, then all collections will be exported. Default: empty
operateOnTypes DatabaseItemType Indicates what should be imported. Default: INDEXES, DOCUMENTS, REVISION_DOCUMENTS, CONFLICTS, DATABASE_RECORD, IDENTITIES, COMPARE_EXCHANGE, SUBSCRIPTIONS
operateOnDatabaseRecordType DatabaseRecordItemType Indicates what should be imported. 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 included in the import. Default: true
removeAnalyzers boolean Should analyzers be removed from Indexes. Default: false
transformScript String JavaScript-based script applied to every exported document. Read more here.
maxStepsForTransformScript int Maximum number of steps that transform script can process before failing. Default: 10000

Example

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

TransformScript

TransformScript exposes the ability to modify or even filter-out the document during the import and export process using the provided JavaScript.

Underneath the JavaScript engine is exactly the same as used for patching operations giving you identical syntax and capabilities with additional ability to filter out documents by throwing a 'skip' exception.

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

this.Freight = 15.3;