how to call cloneCollection from perl

41 views
Skip to first unread message

Rohan M

unread,
Oct 7, 2012, 7:01:43 AM10/7/12
to mongod...@googlegroups.com
 Hi All,
  
   I want to clone a collection from remote server to host server using perl.

    If I try to run the commands from Mongo Console, it works, so no issues of network here.


Trial 1)


my $cmd = Tie::IxHash->new(
                'cloneCollection' => $tableToClone,
                'from'       => 'X.X.X.X:27017',
        );
      my $result = $db->run_command($cmd);
    The $db is same as the remote database. When I run this , the database with collection name ($tableToClone) gets created , which is wrong.
   
    I tried another method,

   my $command = <<CSTART;                                                                                  
        db.cloneCollection('X.X.X.X:27017', '$tableToClone');                                          
 CSTART
    $db->run_command( { 'eval' => MongoDB::Code->new( code => $command )
} );
 
  This also doesn't clone collection

Could somebody help me on this?

Thanks
Rohan;

Rohan M

unread,
Oct 8, 2012, 3:11:47 AM10/8/12
to mongod...@googlegroups.com
Hi All,

Got it working by prepending the database name.

my $cmd = Tie::IxHash->new(
                'cloneCollection' => 'another_db'.$tableToClone,

                'from'       => 'X.X.X.X:27017',
        ); 
Reply all
Reply to author
Forward
0 new messages