1

I have an application that uses embedded RavenDB. I would like to be able to import/export a specific sets of documents (a document with all nested/referenced documents) to a file.

My ideal function would work like:

var session = store.OpenSession();
MyDocument d1 = session.Load<MyDocument>(someId);
ImportExport.Export(store, d1, "file.xyz");

and then with a different IDocumentStore:

ImportExport.Import(store, "file.xyz");
var session = store.OpenSession();
MyDocument d2 = session.Load<MyDocument>(someId);

And of course d1 equals d2 in any way.

AFAIK Smuggler utility exports all documents at once.

My only other idea was using Json.NET to serialize MyDocument object, save it to file, and then deserialize it (and store it). I have a feeling this is a way to go, but will it work with when MyDocument has many other documents inside?

Gerino
  • 1,943
  • 1
  • 16
  • 21
  • I have tested using JsonConvert.Serialize/Deserialize<> from Json.NET - it seems to be working. I am unsure if this is the correct approach (as it basically doesn't really involve Raven). – Gerino Nov 12 '14 at 13:23

2 Answers2

0

You have the Smuggler API to handle this. See:

Export: https://github.com/ravendb/ravendb/blob/d54bfba11995e915cf94f35ef3887fcb7d747033/Raven.Database/Smuggler/SmugglerDatabaseApi.cs#L163

Import: https://github.com/ravendb/ravendb/blob/d54bfba11995e915cf94f35ef3887fcb7d747033/Raven.Database/Smuggler/SmugglerDatabaseApi.cs#L90

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • I've stumbled into those methods, but can you give me an example of exporting only a specific document (with whatever children it has)? Because I'm completly lost at how to call it - it seems to me like it is used for exporting all data from given store? – Gerino Nov 12 '14 at 09:17
  • The code changes since 2014. What version are you using this for? At any rate, I updated the post – Ayende Rahien Feb 20 '19 at 12:03
0

I ended up using the "Raven.Smuggler.exe" program to get things done using "large" ravendump files. It's unclear to me, however, whether this import process [drops and replaces from scratch] or [merges] the data -- I would perform a database drop and re-create before doing the import process below, to guarantee data integrity.

  1. Download a copy of a matching RavenDB build.
  2. Extract it someplace simple (ex: C:\RavenDB-Build-2956)
  3. Invoke the Smuggler.

Command (setup/replace variable placeholders as needed)

    C:\RavenDB-Build-2956\Smuggler\Raven.Smuggler.exe in $instance $dump "-u=$user" "-p=$plainpassword" -d=$dbname

Example variables

starlocke
  • 3,407
  • 2
  • 25
  • 38