use MongoDB; our $mongodb; sub mongodb() { if(!defined($mongodb)){ $log->info("Creating new DB connection"); $mongodb = MongoDB::MongoClient->new; } else{ $log->info("DB connection already exists"); } return $mongodb };