Perl driver question on run_command

247 views
Skip to first unread message

Peter Uhrig

unread,
Aug 16, 2011, 12:46:01 PM8/16/11
to mongodb-user
Dear all,

I'm not even sure whether this is a MongoDB or a Perl question. I'm
trying to pre-split directly from perl since I want to split on ranges
of a binary representation of MD5.
However I cannot get the following command to work:

$db->run_command({"split" => "$dbname.$collection", "middle" =>
{ $shard_key => "$id" }});

It throws:
query error: unrecognized command: middle at /home/hpc/sles/pruhrig/
perl5_nonwoody/lib/perl5/x86_64-linux-gnu-thread-multi/MongoDB/
Collection.pm line 240.

I tried changing it to

$db->run_command({{"split" => "$dbname.$collection"}, {"middle" =>
{ $shard_key => "$id" }}});

query error: unrecognized command: HASH(0xfe9f98) at /home/hpc/sles/
pruhrig/perl5_nonwoody/lib/perl5/x86_64-linux-gnu-thread-multi/MongoDB/
Collection.pm line 240.

Similar if I make the whole thing a list:
$db->run_command([{"split" => "$dbname.$collection"}, ["middle",
{ $shard_key => "$id" }]]);

I'm at a loss. How do I have to formulate the query to run with the
Perl driver?

Thanks a lot and best regards,
Peter

Peter Uhrig

unread,
Aug 17, 2011, 8:47:13 AM8/17/11
to mongodb-user
Ok, found the problem with the help of a colleague (and by reading the
manual again, although I thought I had read everything about the
problem...). In case anyone has the same problem, the solution goes
like this:

use Tie::IxHash;
my %myhash;
my $t = tie(%myhash, "Tie::IxHash");
%myhash = ("split" => "$dbname.$collection", "middle" => { $shard_key
=> "$id" });
$db->run_command(\%myhash);

So there were problems with braces and with the order of the commands
which can only be guaranteed by using Tie::IxHash (as mentioned in the
Perl MongoDB Tutorial).

All the best,
Peter
Reply all
Reply to author
Forward
0 new messages