Select Git revision
Gerhard Gonter authored
added config options db_auth and db_work to more clearly specify which db should be used for authentication and which should be used to actually work with
MongoDB.pm 9.54 KiB
# $Id: MongoDB.pm,v 1.19 2017/08/02 10:05:09 gonter Exp $
package Util::MongoDB;
use strict;
use MongoDB;
use Data::Dumper;
my $patched;
sub new
{
my $class= shift;
my $obj= bless {}, $class;
$obj->set (@_);
$obj;
}
sub set
{
my $obj= shift;
my %par= @_;
foreach my $par (keys %par)
{
$obj->{$par}= $par{$par};
}
}
sub connect_mongodb
{
my $self= shift;
my $col_name= shift;
print STDERR join (' ', caller()), " using connect_mongodb() is deprecated, uses attach() instead!\n";
attach ($self, $col_name);
}
sub attach
{
my $self= shift;
my $col_name= shift;
my $mdb= $self->{_mdb};
my $col;
if (defined ($mdb))
{
return $mdb unless (defined ($col_name));
$col= $self->{_col}->{$col_name};
return ($mdb, $col) if (defined ($col));
}
else
{
($mdb, $col)= Util::MongoDB::connect ($self->{MongoDB});
}
unless (defined ($mdb))
{
print "ATTN: can not connect to MongoDB: ", Dumper ($mdb);
return undef;
}
$self->{_mdb}= $mdb;
return $mdb unless (defined ($col_name));