@@ -27,7 +27,7 @@ class MongodbConnectionFactory implements ConnectionFactory
2727 *
2828 * or
2929 *
30- * mongodb://127.0.0.1:27017/dbname ?polling_interval=1000&enqueue_collection=enqueue
30+ * mongodb://127.0.0.1:27017/defaultauthdb ?polling_interval=1000&enqueue_database=enqueue &enqueue_collection=enqueue
3131 *
3232 * @param array|string|null $config
3333 */
@@ -38,7 +38,10 @@ public function __construct($config = 'mongodb:')
3838 } elseif (is_string ($ config )) {
3939 $ config = $ this ->parseDsn ($ config );
4040 } elseif (is_array ($ config )) {
41- $ config = $ this ->parseDsn (empty ($ config ['dsn ' ]) ? 'mongodb: ' : $ config ['dsn ' ]);
41+ $ config = array_replace (
42+ $ config ,
43+ $ this ->parseDsn (empty ($ config ['dsn ' ]) ? 'mongodb: ' : $ config ['dsn ' ])
44+ );
4245 } else {
4346 throw new \LogicException ('The config must be either an array of options, a DSN string or null ' );
4447 }
@@ -86,6 +89,8 @@ public static function parseDsn(string $dsn): array
8689 ];
8790 }
8891 $ config ['dsn ' ] = $ dsn ;
92+ // FIXME this is NOT a dbname but rather authdb. But removing this would be a BC break.
93+ // see: https://github.com/php-enqueue/enqueue-dev/issues/1027
8994 if (isset ($ parsedUrl ['path ' ]) && '/ ' !== $ parsedUrl ['path ' ]) {
9095 $ pathParts = explode ('/ ' , $ parsedUrl ['path ' ]);
9196 //DB name
@@ -103,6 +108,9 @@ public static function parseDsn(string $dsn): array
103108 if (!empty ($ queryParts ['enqueue_collection ' ])) {
104109 $ config ['collection_name ' ] = $ queryParts ['enqueue_collection ' ];
105110 }
111+ if (!empty ($ queryParts ['enqueue_database ' ])) {
112+ $ config ['dbname ' ] = $ queryParts ['enqueue_database ' ];
113+ }
106114 }
107115
108116 return $ config ;
0 commit comments