@@ -27,7 +27,7 @@ class MongodbConnectionFactory implements ConnectionFactory
27
27
*
28
28
* or
29
29
*
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
31
31
*
32
32
* @param array|string|null $config
33
33
*/
@@ -38,7 +38,10 @@ public function __construct($config = 'mongodb:')
38
38
} elseif (is_string ($ config )) {
39
39
$ config = $ this ->parseDsn ($ config );
40
40
} 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
+ );
42
45
} else {
43
46
throw new \LogicException ('The config must be either an array of options, a DSN string or null ' );
44
47
}
@@ -86,6 +89,8 @@ public static function parseDsn(string $dsn): array
86
89
];
87
90
}
88
91
$ 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
89
94
if (isset ($ parsedUrl ['path ' ]) && '/ ' !== $ parsedUrl ['path ' ]) {
90
95
$ pathParts = explode ('/ ' , $ parsedUrl ['path ' ]);
91
96
//DB name
@@ -103,6 +108,9 @@ public static function parseDsn(string $dsn): array
103
108
if (!empty ($ queryParts ['enqueue_collection ' ])) {
104
109
$ config ['collection_name ' ] = $ queryParts ['enqueue_collection ' ];
105
110
}
111
+ if (!empty ($ queryParts ['enqueue_database ' ])) {
112
+ $ config ['dbname ' ] = $ queryParts ['enqueue_database ' ];
113
+ }
106
114
}
107
115
108
116
return $ config ;
0 commit comments