couchrest_model/utils/remap.rb

28 lines
627 B
Ruby
Raw Normal View History

2008-08-03 23:17:58 +02:00
require 'rubygems'
require 'couchrest'
# set the source db and map view
2008-12-14 12:05:02 +01:00
source = CouchRest.new("http://127.0.0.1:5984").database('source-db')
2008-08-03 23:17:58 +02:00
source_view = 'mydesign/view-map'
# set the target db
2008-12-14 12:05:02 +01:00
target = CouchRest.new("http://127.0.0.1:5984").database('target-db')
2008-08-03 23:17:58 +02:00
pager = CouchRest::Pager.new(source)
# pager will yield once per uniq key in the source view
pager.key_reduce(source_view, 10000) do |key, values|
# create a doc from the key and the values
example_doc = {
:key => key,
:values => values.uniq
}
target.save(example_doc)
# keep us up to date with progress
puts k if (rand > 0.9)
end