jgauffin
jgauffin

Reputation: 101150

RavenDB: Convert a document property to another type

I'm currently developing an application where I change the document a lot as I go forward (a small project to learn stuff like RavenDB). Some changes are not backwards compatible, which leads to JSON deserialization failures when I try to fetch documents.

Are there some way that I convert a property from the old type to a new one during deserialization? I'm using Raven.Client.Lightweight as client library.

Example:

I had a property named AllProperties in a class which was a Dictionary<string,string>. I changed the type from dictionary to a class called MetadataItemCollection.

Upvotes: 3

Views: 956

Answers (2)

Ayende Rahien
Ayende Rahien

Reputation: 22956

If you are doing this during development, you are probably better off just deleting old docs and recreating them If you are doing this in production, take a look at the posts that dlang has posted, they discuss those specific issues.

Upvotes: 3

Daniel Lang
Daniel Lang

Reputation: 6839

As in any other database-solution I suggest you roll your favourite migrations-framework for such kind of things. You will probably want to do set-based operations on documents.

Interesting is, Ayende is going to publish two articles about ravendb migrations in the next few days, however, google has already indexed them and you can access these articles here:

RavenDB Migrations: When to execute?

RavenDB Migrations: Rolling Updates

Ayende, please forgive me... ;)

Upvotes: 6

Related Questions