eval{
(my $host,my $port)=split(/:/,$host_port_iter);
my $url = "mongodb://".$host.":".$port;
#my $authdbname = 'admin';
$client = MongoDB::MongoClient->new(
host => $url.'/'.$dbname,
username => $username,
password => $password,
);
$client->connect;
my $database = $client->get_database($dbname);
$collection = $database->get_collection($dbcollections);
(my $host,my $port)=split(/:/,$host_port_iter);
my $url = "mongodb://".$host.":".$port;
#my $authdbname = 'admin';
$client = MongoDB::MongoClient->new(
host => $url.'/'.$dbname,
username => $username,
password => $password,
);
$client->connect;
my $database = $client->get_database($dbname);
$collection = $database->get_collection($dbcollections);
};
eval{
@objects= $collection->find($myhashcommand)->limit($limitcount)->all();
print Data::Dumper->Dumper(\@objects);
};
if ($@ ne ''){
$result = $host_port.$@;
}
foreach my $myarry (@objects)
{
print "----------------"."\n";
$result.="{";
foreach my $key ( keys %$myarry ){
$result.=" $key";
$result.=":";
$result.="${$myarry}{$key}".",";
}
$result = substr($result,0,length($result)-1);
$result.="}"."\n"; #去除最后一个,号
}
print $result;