Created
January 11, 2023 16:06
-
-
Save luis-fss/f49c0587e145e5afdd6372a39677ff1b to your computer and use it in GitHub Desktop.
RavenDB: move all documents from one database to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading.Tasks; | |
using Raven.Client.Documents; | |
using Raven.Client.ServerWide.Operations; | |
public class RavenDBMerger | |
{ | |
readonly IDocumentStore _store; | |
public RavenDBMerger(IDocumentStore store) | |
{ | |
_store = store; | |
} | |
public async Task MergeDatabases() | |
{ | |
string sourceDbName = "source-database"; | |
var sourceDb = _store.Maintenance.Server.Send(new GetDatabaseRecordOperation(sourceDbName)); | |
if (sourceDb != null) | |
{ | |
var smugglerFrom = _store.Smuggler.ForDatabase(sourceDbName); | |
var smugglerTo = _store.Smuggler.ForDatabase("target-database"); | |
await smugglerFrom.ExportAsync(new Raven.Client.Documents.Smuggler.DatabaseSmugglerExportOptions(), smugglerTo); | |
_store.Maintenance.Server.Send(new DeleteDatabasesOperation(sourceDbName, hardDelete: true)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://stackoverflow.com/questions/66249026/how-to-move-all-documents-from-one-ravendb-database-to-another