The setup for this question is a bit elaborate, please bear with me :)
My scenario is that of migrating data from relational table form to document collection form ("ETL"). My source data is represented in a relational table where each row describes a "Person" and one of his/her "Addresses". (Naturally this table isn't normalized).
A simplified example would be:
PersonId PersonName AddressId AddressText
1 John Doe 1 Somewhere
1 John Doe 2 Elsewhere
2 Jane Doe 3 Some other place
To complicate things, some of the rows can update previous existing values. Ex:
PersonId PersonName AddressId AddressText
1 John Doe 1 A new address
I would like to migrate this data into a document collection in a document store (DB) for easy retrieval of specific Person entities with all their related Addresses. To begin with I am considering a single document per Person, like so:
{
"id":"1",
"addresses":[
{
"id":"1",
"text":"A new address"
},
{
"id":"2",
"text":"Elsewhere"
}
]
}
MY QUESTION IS: What is the best way to merge the table rows into a document?
Is the best approach to take a document store that supports partial updates (MongoDB, RavenDB) and use that feature?
Or maybe I should fetch the document as a whole from the document DB, update it in my business logic layer and save it whole back to the DB?
Or should I aim for a different document representation of the data altogether?