/[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

Diff of /bin/couchdb2mongodb.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 478 by dpavlin, Sat Jan 23 15:06:59 2010 UTC revision 479 by dpavlin, Sat Jan 23 17:49:07 2010 UTC
# Line 13  use Time::HiRes qw(time); Line 13  use Time::HiRes qw(time);
13  use File::Path qw(make_path remove_tree);  use File::Path qw(make_path remove_tree);
14  use MongoDB;  use MongoDB;
15    
16  my $name = 'pxelator';  my $name = shift @ARGV || 'pxelator';
17    
18  my $conn = MongoDB::Connection->new;  my $conn = MongoDB::Connection->new;
19  my $db = $conn->get_database( $name );  my $db = $conn->get_database( $name );
# Line 46  get_chunk($sock); Line 46  get_chunk($sock);
46    
47  my $total = <$sock>;  my $total = <$sock>;
48  $total =~ s{^.*total_rows\D+(\d+).+$}{$1};  $total =~ s{^.*total_rows\D+(\d+).+$}{$1};
49  warn "# total: $total\n";  
50    $|=1;
51    print "# $name total: $total\n";
52    
53    my $start_t = time();
54    my $count = 0;
55    
56    
57  while(<$sock>) {  while(<$sock>) {
58          if ( /"id":"([^"]+)"/ ) {          if ( /"id":"([^"]+)"/ ) {
# Line 54  while(<$sock>) { Line 60  while(<$sock>) {
60                  s/,[\r\n]+$//; # cleanup JSON                  s/,[\r\n]+$//; # cleanup JSON
61                  my $json = from_json( $_ );                  my $json = from_json( $_ );
62                  $audit->insert( $json->{doc} );                  $audit->insert( $json->{doc} );
63                  print STDERR ".";                  printf " %d/%d %.2f%% %.2f/s\r", $count, $total
64                            , ( $count / $total ) * 100
65                            , ( $count / ( time() - $start_t ) )
66                            if ++$count % 1000 == 0;
67          } else {          } else {
68                  warn "UNKNOWN: $_";                  warn "UNKNOWN: $_";
69          }          }

Legend:
Removed from v.478  
changed lines
  Added in v.479

  ViewVC Help
Powered by ViewVC 1.1.26