From 0ccaee3db458db776c6a285939f74d479cf5dcc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bertu=C4=9F=20Fahri=20=C3=96ZER?= Date: Sun, 5 Feb 2023 04:23:47 +0300 Subject: [PATCH] mongodb+srv bug fixed for mongodb atlas --- .gitignore | 0 README.md | 0 app/Config/SimpleConfig.php | 0 app/Libraries/Mongo.php | 29 ++++++++++++++++++++--------- app/Models/CommonModel.php | 0 composer.json | 0 6 files changed, 20 insertions(+), 9 deletions(-) mode change 100755 => 100644 .gitignore mode change 100755 => 100644 README.md mode change 100755 => 100644 app/Config/SimpleConfig.php mode change 100755 => 100644 app/Libraries/Mongo.php mode change 100755 => 100644 app/Models/CommonModel.php mode change 100755 => 100644 composer.json diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/app/Config/SimpleConfig.php b/app/Config/SimpleConfig.php old mode 100755 new mode 100644 diff --git a/app/Libraries/Mongo.php b/app/Libraries/Mongo.php old mode 100755 new mode 100644 index ee95e89..55af8fc --- a/app/Libraries/Mongo.php +++ b/app/Libraries/Mongo.php @@ -23,15 +23,26 @@ function __construct($selectedDB='default') $this->mongoConnectionInfos = new MongoConfig(); foreach ($this->mongoConnectionInfos->dbInfo as $key=>$dbInfo) { if($key===$selectedDB) { - $this->m = new client($this->mongoConnectionInfos->dbInfo[$key]->srv . "://{$this->mongoConnectionInfos->dbInfo[$key]->hostname}:{$this->mongoConnectionInfos->dbInfo[$key]->port}/{$this->mongoConnectionInfos->dbInfo[$key]->db}", - [$this->mongoConnectionInfos->dbInfo[$key]->authMechanism, - 'username' => $this->mongoConnectionInfos->dbInfo[$key]->userName, - 'password' => $this->mongoConnectionInfos->dbInfo[$key]->password, - 'journal' => $this->mongoConnectionInfos->dbInfo[$key]->journal, - 'w' => $this->mongoConnectionInfos->dbInfo[$key]->write_concerns, - 'readConcern' => $this->mongoConnectionInfos->dbInfo[$key]->read_concern, - 'readPreference' => $this->mongoConnectionInfos->dbInfo[$key]->read_preference, - ], $this->mongoConnectionInfos->dbInfo[$key]->ca_file); + if($this->mongoConnectionInfos->dbInfo[$key]->srv==='mongodb') + $this->m = new client($this->mongoConnectionInfos->dbInfo[$key]->srv . "://{$this->mongoConnectionInfos->dbInfo[$key]->hostname}:{$this->mongoConnectionInfos->dbInfo[$key]->port}/{$this->mongoConnectionInfos->dbInfo[$key]->db}", + [$this->mongoConnectionInfos->dbInfo[$key]->authMechanism, + 'username' => $this->mongoConnectionInfos->dbInfo[$key]->userName, + 'password' => $this->mongoConnectionInfos->dbInfo[$key]->password, + 'journal' => $this->mongoConnectionInfos->dbInfo[$key]->journal, + 'w' => $this->mongoConnectionInfos->dbInfo[$key]->write_concerns, + 'readConcern' => $this->mongoConnectionInfos->dbInfo[$key]->read_concern, + 'readPreference' => $this->mongoConnectionInfos->dbInfo[$key]->read_preference, + ], $this->mongoConnectionInfos->dbInfo[$key]->ca_file); + else { + $this->m = new client($this->mongoConnectionInfos->dbInfo[$key]->srv . "://{$this->mongoConnectionInfos->dbInfo[$key]->userName}:{$this->mongoConnectionInfos->dbInfo[$key]->password}@{$this->mongoConnectionInfos->dbInfo[$key]->hostname}/{$this->mongoConnectionInfos->dbInfo[$key]->db}", + [ + 'journal' => $this->mongoConnectionInfos->dbInfo[$key]->journal, + 'w' => $this->mongoConnectionInfos->dbInfo[$key]->write_concerns, + 'readConcern' => $this->mongoConnectionInfos->dbInfo[$key]->read_concern, + 'readPreference' => $this->mongoConnectionInfos->dbInfo[$key]->read_preference, + 'ssl'=>true + ]); + } $this->mongoConnectionInfos->db = $dbInfo->db; $this->mongoConnectionInfos->prefix = $dbInfo->prefix; } diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php old mode 100755 new mode 100644 diff --git a/composer.json b/composer.json old mode 100755 new mode 100644