Converting document structure

We have come up with following situation when trying to evaluate couchbase server for a new project.

Lets say we have 10000 User documents as following structure.

{
username: ‘myusername’,
firstName: ‘Mike’,
lastName: ‘Rodgers’
}

Now lets say next version of our application we need to re-factor above document as follows.

{
username: ‘myusername’,
name: {
firstName: 'Mike’
lastName: ‘Rodgers’
}
}

Is there any straight forward way to do this in couchbase at once. (For example in SQL databases we can simply run data migration script and convert old data in to new structure )

Thanks

This can also be done with a migration script, with the following pattern:

[1] Create a primary index, using map reduce with the meta id for each document
[2] That index will allow you to iterate through all of the documents in a bucket, and make the schema changes, or migrate the documents to a new bucket with the changes to the schema.

Dear Todd,

Thanks for the explanation. However I am still not clear on the [2] step.

  1. Is there any internal way within the couchbase in order to do this. Or else do we have to write an external program (PHP, Java, NodeJS, etc) for this ?