Skip to content

Instantly share code, notes, and snippets.

@luis-fss
Created January 11, 2023 16:06
Show Gist options
  • Save luis-fss/f49c0587e145e5afdd6372a39677ff1b to your computer and use it in GitHub Desktop.
Save luis-fss/f49c0587e145e5afdd6372a39677ff1b to your computer and use it in GitHub Desktop.
RavenDB: move all documents from one database to another
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