diff --git a/README.md b/README.md index 041a0d0..0d15ab7 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,8 @@ Finally, add a MongoDB hash at the end of your `app/config/database.php` (so, ou If needed (for MongoHq and the likes), you can specify a `username` and `password` in this array as well. +Any other options will be added as GET parameters to the DSN. + ### Authentification To use Mongovel as your Auth provided, you'll simply need to go in the `app/config/auth.php` file and set `mongo` as your driver. diff --git a/src/Mongovel/DB.php b/src/Mongovel/DB.php index 7722c20..057eb0f 100644 --- a/src/Mongovel/DB.php +++ b/src/Mongovel/DB.php @@ -55,10 +55,24 @@ public function setDatabaseDSN($server = null, $database = null) $this->database = $dsn['database']; if (isset($dsn['username']) && isset($dsn['password'])) { - $this->server = sprintf('mongodb://%s:%s@%s:%d/%s', $dsn['username'], $dsn['password'], $dsn['host'], $dsn['port'], $dsn['database']); + $this->server = sprintf('mongodb://%s:%s@%s:%d/%s/', $dsn['username'], $dsn['password'], $dsn['host'], $dsn['port'], $dsn['database']); } else { - $this->server = sprintf('mongodb://%s:%d', $dsn['host'], $dsn['port']); + $this->server = sprintf('mongodb://%s:%d/', $dsn['host'], $dsn['port']); + } + + $options = array_diff_key($dsn, array( + 'host' => true, + 'port' => true, + 'database' => true, + 'username' => true, + 'password' => true, + )); + $options = array_map(function($key, $value) { + return $key . '=' . $value; + }, array_keys($options), array_values($options)); + if ($options) { + $this->server .= '?' . implode('&', $options); } } }