Perl driver question on run_command

242 visualizzazioni
Passa al primo messaggio da leggere

Peter Uhrig

da leggere,
16 ago 2011, 12:46:0116/08/11
a 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

da leggere,
17 ago 2011, 08:47:1317/08/11
a 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
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi