From 96924771f3d1a3eb71f80efcc4a35243436bc6b7 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Mon, 5 Aug 2019 11:16:46 +0200 Subject: [PATCH] allow use of different protocol for mongodb driver --- database/mongodb/custom/driver.pm | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/database/mongodb/custom/driver.pm b/database/mongodb/custom/driver.pm index ea8f8a3bc..866b6c7e9 100644 --- a/database/mongodb/custom/driver.pm +++ b/database/mongodb/custom/driver.pm @@ -43,12 +43,13 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, - "ssl-opt:s@" => { name => 'ssl_opt' }, + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port' }, + "protocol:s" => { name => 'protocol' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "timeout:s" => { name => 'timeout' }, + "ssl-opt:s@" => { name => 'ssl_opt' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'DRIVER OPTIONS', once => 1); @@ -86,6 +87,7 @@ sub check_options { $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : 'localhost'; $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 27017; + $self->{protocol} = (defined($self->{option_results}->{protocol})) ? $self->{option_results}->{protocol} : 'mongodb'; $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; $self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : ''; $self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : ''; @@ -117,7 +119,7 @@ sub connect { my $encoded_username = $uri->encode($self->{username}); my $encoded_password = $uri->encode($self->{password}); - $uri = 'mongodb://'; + $uri = $self->{protocol} . '://'; $uri .= $encoded_username . ':' . $encoded_password . '@' if ($encoded_username ne '' && $encoded_password ne ''); $uri .= $self->{hostname} if ($self->{hostname} ne ''); $uri .= ':' . $self->{port} if ($self->{port} ne ''); @@ -208,6 +210,11 @@ MongoDB server hostname. Port used (Default: 27017) +=item B<--protocol> + +Protocol used (Default: mongodb) +DNS Seedlist Connection Format can be specified, i.e. 'mongodb+srv' + =item B<--username> MongoDB username.