Skip to content

Commit

Permalink
mongodb+srv bug fixed for mongodb atlas
Browse files Browse the repository at this point in the history
  • Loading branch information
bertugfahriozer committed Feb 5, 2023
1 parent 20352e0 commit 0ccaee3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
Empty file modified .gitignore
100755 → 100644
Empty file.
Empty file modified README.md
100755 → 100644
Empty file.
Empty file modified app/Config/SimpleConfig.php
100755 → 100644
Empty file.
29 changes: 20 additions & 9 deletions app/Libraries/Mongo.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Empty file modified app/Models/CommonModel.php
100755 → 100644
Empty file.
Empty file modified composer.json
100755 → 100644
Empty file.

0 comments on commit 0ccaee3

Please sign in to comment.