@@ -168,7 +168,7 @@ public function __debugInfo(): array
168
168
*/
169
169
public function __get (string $ databaseName ): Database
170
170
{
171
- return $ this ->selectDatabase ($ databaseName );
171
+ return $ this ->getDatabase ($ databaseName );
172
172
}
173
173
174
174
/**
@@ -230,6 +230,37 @@ public function dropDatabase(string $databaseName, array $options = []): void
230
230
$ operation ->execute ($ server );
231
231
}
232
232
233
+ /**
234
+ * Returns a collection instance.
235
+ *
236
+ * If the collection does not exist in the database, it is not created when
237
+ * invoking this method.
238
+ *
239
+ * @see Collection::__construct() for supported options
240
+ * @throws InvalidArgumentException for parameter/option parsing errors
241
+ */
242
+ public function getCollection (string $ databaseName , string $ collectionName , array $ options = []): Collection
243
+ {
244
+ $ options += ['typeMap ' => $ this ->typeMap , 'builderEncoder ' => $ this ->builderEncoder ];
245
+
246
+ return new Collection ($ this ->manager , $ databaseName , $ collectionName , $ options );
247
+ }
248
+
249
+ /**
250
+ * Returns a database instance.
251
+ *
252
+ * If the database does not exist on the server, it is not created when
253
+ * invoking this method.
254
+ *
255
+ * @see Database::__construct() for supported options
256
+ */
257
+ public function getDatabase (string $ databaseName , array $ options = []): Database
258
+ {
259
+ $ options += ['typeMap ' => $ this ->typeMap , 'builderEncoder ' => $ this ->builderEncoder ];
260
+
261
+ return new Database ($ this ->manager , $ databaseName , $ options );
262
+ }
263
+
233
264
/**
234
265
* Return the Manager.
235
266
*/
@@ -329,9 +360,7 @@ final public function removeSubscriber(Subscriber $subscriber): void
329
360
*/
330
361
public function selectCollection (string $ databaseName , string $ collectionName , array $ options = []): Collection
331
362
{
332
- $ options += ['typeMap ' => $ this ->typeMap , 'builderEncoder ' => $ this ->builderEncoder ];
333
-
334
- return new Collection ($ this ->manager , $ databaseName , $ collectionName , $ options );
363
+ return $ this ->getCollection ($ databaseName , $ collectionName , $ options );
335
364
}
336
365
337
366
/**
@@ -344,9 +373,7 @@ public function selectCollection(string $databaseName, string $collectionName, a
344
373
*/
345
374
public function selectDatabase (string $ databaseName , array $ options = []): Database
346
375
{
347
- $ options += ['typeMap ' => $ this ->typeMap , 'builderEncoder ' => $ this ->builderEncoder ];
348
-
349
- return new Database ($ this ->manager , $ databaseName , $ options );
376
+ return $ this ->getDatabase ($ databaseName , $ options );
350
377
}
351
378
352
379
/**
0 commit comments