/[pxelator]/bin/couchdb2mongodb.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /bin/couchdb2mongodb.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 478 - (hide annotations)
Sat Jan 23 15:06:59 2010 UTC (14 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 1093 byte(s)
migrate data from CouchDB to MongoDB

1 dpavlin 478 #!/usr/bin/perl
2    
3     # http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
4    
5     use warnings;
6     use strict;
7    
8     use IO::Socket::INET;
9     use Storable qw();
10     use JSON;
11     use Data::Dump qw(dump);
12     use Time::HiRes qw(time);
13     use File::Path qw(make_path remove_tree);
14     use MongoDB;
15    
16     my $name = 'pxelator';
17    
18     my $conn = MongoDB::Connection->new;
19     my $db = $conn->get_database( $name );
20     my $audit = $db->get_collection("audit");
21    
22     sub couchdb_socket {
23     IO::Socket::INET->new(
24     PeerAddr => '10.60.0.91',
25     PeerPort => 5984,
26     Proto => 'tcp',
27     ) || die $!;
28     }
29    
30     sub get_chunk {
31     my $sock = shift;
32     my $chunk;
33     while(<$sock>) {
34     $chunk .= $_;
35     last if /^[\n\r]+$/;
36     }
37     # warn "# $sock\n$chunk\n";
38     return $chunk;
39     }
40    
41     my $sock = couchdb_socket;
42    
43     print $sock "GET /$name/_all_docs?include_docs=true HTTP/1.0\r\n\r\n";
44    
45     get_chunk($sock);
46    
47     my $total = <$sock>;
48     $total =~ s{^.*total_rows\D+(\d+).+$}{$1};
49     warn "# total: $total\n";
50    
51     while(<$sock>) {
52     if ( /"id":"([^"]+)"/ ) {
53    
54     s/,[\r\n]+$//; # cleanup JSON
55     my $json = from_json( $_ );
56     $audit->insert( $json->{doc} );
57     print STDERR ".";
58     } else {
59     warn "UNKNOWN: $_";
60     }
61     }
62    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26