#file: test.Mongo.pl
use strict;
use warnings;
use MongoDB; # also loads MongoDB::MongoClient
use Data::Dumper;
my $connect_string=$ARGV[0];
my $client = MongoDB::MongoClient->new({'host' => $connect_string});
my $doc = $client->get_database('mydb')->get_collection('mycoll')->find_one();
$client->disconnect;
print Dumper $doc;
####
#file: test.Mango.pl
use strict;
use warnings;
use Mango;
use feature 'state';
use Data::Dumper;
my $connect_string=$ARGV[0];
sub mango { state $m = Mango->new($connect_string)}
my $doc = mango->db('mydb')->collection('mycoll')->find_one();
print Dumper $doc;
####
> perl test.Mango.pl "$MONGO_STRING" #OK.5
-- Emit connect in Mojo::IOLoop::Client (1)
-- Emit write in Mojo::IOLoop::Stream (0)
-- Emit drain in Mojo::IOLoop::Stream (0)
-- Emit read in Mojo::IOLoop::Stream (1)
-- Emit write in Mojo::IOLoop::Stream (0)
-- Emit drain in Mojo::IOLoop::Stream (0)
-- Emit read in Mojo::IOLoop::Stream (1)
-- Emit write in Mojo::IOLoop::Stream (0)
-- Emit drain in Mojo::IOLoop::Stream (0)
-- Emit read in Mojo::IOLoop::Stream (1)
-- Emit write in Mojo::IOLoop::Stream (0)
-- Emit drain in Mojo::IOLoop::Stream (0)
-- Emit read in Mojo::IOLoop::Stream (1)
-- Emit connection in Mango (0)
-- Emit finish in Mojo::IOLoop::Delay (1)
-- Emit write in Mojo::IOLoop::Stream (0)
-- Emit drain in Mojo::IOLoop::Stream (0)
-- Emit read in Mojo::IOLoop::Stream (1)
$VAR1 = {
'_id' => bless( {
'oid' => '_L+.\''
}, 'Mango::BSON::ObjectID' ),
.....
};
####
> perl test.Mango.pl "$ATLAS_STRING" # ERROR: Premature connection close at /var/..../local/lib/perl5/Mango/Cursor/Query.pm line 112.
-- Emit connect in Mojo::IOLoop::Client (1)
-- Emit write in Mojo::IOLoop::Stream (0)
-- Emit drain in Mojo::IOLoop::Stream (0)
-- Emit close in Mojo::IOLoop::Stream (2)
Premature connection close at /var/..../local/lib/perl5/Mango/Cursor/Query.pm line 112.
####
Mojo::IOLoop::Stream::_read(/var/..../local/lib/perl5/Mojo/IOLoop/Stream.pm:103):
103: return if $! == EAGAIN || $! == EINTR || $! == EWOULDBLOCK;
DB<8> x $!
0 'Connection reset by peer'
####
my %extra;
$extra{replica_set_name} = 'xxxx';
$extra{tls} = 1; #Note, it's "tls" (not "ssl" like it would be in the connection string)
sub mango { state $m = Mango->new($connect_string, %extra);}