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
property.
ForDatabase
By default, the DocumentStore.Smuggler
works on the default document store database from the DocumentStore.Database
property.
In order to switch it to a different database use the .ForDatabase
method.
var northwindSmuggler = store
.Smuggler
.ForDatabase("Northwind");
Export
Syntax
Task<Operation> ExportAsync(
DatabaseSmugglerExportOptions options,
DatabaseSmuggler toDatabase,
CancellationToken token = default(CancellationToken));
Task<Operation> ExportAsync(
DatabaseSmugglerExportOptions options,
string toFile,
CancellationToken token = default(CancellationToken));
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 |
token | CancellationToken |
Token used to cancel the operation |
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 , ReplicationHubCertificates , Identities , CompareExchange , Attachments , CounterGroups , Subscriptions , TimeSeries |
OperateOnDatabaseRecordTypes | DatabaseRecordItemType |
Indicates what should be exported from database record. Default: Client , ConflictSolverConfig , Expiration , ExternalReplications , PeriodicBackups , RavenConnectionStrings , RavenEtls , Revisions , Settings , SqlConnectionStrings , Sorters , SqlEtls , HubPullReplications , SinkPullReplications , TimeSeries , DocumentsCompression , Analyzers , LockMode , OlapConnectionStrings , OlapEtls , ElasticSearchConnectionStrings , ElasticSearchEtls , PostgreSQLIntegration , QueueConnectionStrings , QueueEtls , IndexesHistory , Refresh , DataArchival |
IncludeExpired | bool |
Should expired documents be exported. Default: true |
IncludeArtificial | bool |
Should artificial documents be exported. Default: false |
IncludeArchived | bool |
Should archived documents be exported. Default: true |
RemoveAnalyzers | bool |
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 the transform script can process before failing. Default: 10000 |
Example
// export only Indexes and Documents to a given file
var exportOperation = await store
.Smuggler
.ExportAsync(
new DatabaseSmugglerExportOptions
{
OperateOnTypes = DatabaseItemType.Indexes
| DatabaseItemType.Documents
},
@"C:\ravendb-exports\Northwind.ravendbdump",
token);
await exportOperation.WaitForCompletionAsync();
Import
Syntax
Task<Operation> ImportAsync(
DatabaseSmugglerImportOptions options,
Stream stream,
CancellationToken token = default(CancellationToken));
Task<Operation> ImportAsync(
DatabaseSmugglerImportOptions options,
string fromFile,
CancellationToken token = default(CancellationToken));
Parameters | ||
---|---|---|
options | DatabaseSmugglerImportOptions |
Options that will be used during the import. Read more here. |
stream | Stream |
Stream with data to import |
fromFile | string |
Path to a file from which data will be imported |
token | CancellationToken |
Token used to cancel the operation |
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 imported. Default: empty |
OperateOnTypes | DatabaseItemType |
Indicates what should be imported. Default: Indexes , Documents , RevisionDocuments , Conflicts , DatabaseRecord , ReplicationHubCertificates , Identities , CompareExchange , Attachments , CounterGroups , Subscriptions , TimeSeries |
OperateOnDatabaseRecordTypes | DatabaseRecordItemType |
Indicates what should be imported from database record. Default: Client , ConflictSolverConfig , Expiration , ExternalReplications , PeriodicBackups , RavenConnectionStrings , RavenEtls , Revisions , Settings , SqlConnectionStrings , Sorters , SqlEtls , HubPullReplications , SinkPullReplications , TimeSeries , DocumentsCompression , Analyzers , LockMode , OlapConnectionStrings , OlapEtls , ElasticSearchConnectionStrings , ElasticSearchEtls , PostgreSQLIntegration , QueueConnectionStrings , QueueEtls , IndexesHistory , Refresh , DataArchival |
IncludeExpired | bool |
Should expired documents be imported. Default: true |
IncludeArtificial | bool |
Should artificial documents be imported. Default: false |
IncludeArchived | bool |
Should archived documents be imported. Default: true |
RemoveAnalyzers | bool |
Should analyzers be removed from Indexes. Default: false |
TransformScript | string |
JavaScript-based script applied to every imported document. Read more here. |
MaxStepsForTransformScript | int |
Maximum number of steps that the transform script can process before failing. Default: 10000 |
Example
// import only Documents from a given file
var importOperation = await store
.Smuggler
.ImportAsync(
new DatabaseSmugglerImportOptions
{
OperateOnTypes = DatabaseItemType.Documents
},
// import the .ravendbdump file that you exported (i.e. in the export example above)
@"C:\ravendb-exports\Northwind.ravendbdump",
token);
await importOperation.WaitForCompletionAsync();
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;