@@ -174,7 +174,7 @@ public function __debugInfo()
174
174
*/
175
175
public function __get (string $ databaseName )
176
176
{
177
- return $ this ->selectDatabase ($ databaseName );
177
+ return $ this ->getDatabase ($ databaseName );
178
178
}
179
179
180
180
/**
@@ -247,6 +247,37 @@ public function dropDatabase(string $databaseName, array $options = [])
247
247
return $ operation ->execute ($ server );
248
248
}
249
249
250
+ /**
251
+ * Returns a collection instance.
252
+ *
253
+ * If the collection does not exist in the database, it is not created when
254
+ * invoking this method.
255
+ *
256
+ * @see Collection::__construct() for supported options
257
+ * @throws InvalidArgumentException for parameter/option parsing errors
258
+ */
259
+ public function getCollection (string $ databaseName , string $ collectionName , array $ options = []): Collection
260
+ {
261
+ $ options += ['typeMap ' => $ this ->typeMap , 'builderEncoder ' => $ this ->builderEncoder ];
262
+
263
+ return new Collection ($ this ->manager , $ databaseName , $ collectionName , $ options );
264
+ }
265
+
266
+ /**
267
+ * Returns a database instance.
268
+ *
269
+ * If the database does not exist on the server, it is not created when
270
+ * invoking this method.
271
+ *
272
+ * @see Database::__construct() for supported options
273
+ */
274
+ public function getDatabase (string $ databaseName , array $ options = []): Database
275
+ {
276
+ $ options += ['typeMap ' => $ this ->typeMap , 'builderEncoder ' => $ this ->builderEncoder ];
277
+
278
+ return new Database ($ this ->manager , $ databaseName , $ options );
279
+ }
280
+
250
281
/**
251
282
* Return the Manager.
252
283
*
@@ -354,9 +385,7 @@ final public function removeSubscriber(Subscriber $subscriber): void
354
385
*/
355
386
public function selectCollection (string $ databaseName , string $ collectionName , array $ options = [])
356
387
{
357
- $ options += ['typeMap ' => $ this ->typeMap , 'builderEncoder ' => $ this ->builderEncoder ];
358
-
359
- return new Collection ($ this ->manager , $ databaseName , $ collectionName , $ options );
388
+ return $ this ->getCollection ($ databaseName , $ collectionName , $ options );
360
389
}
361
390
362
391
/**
@@ -370,9 +399,7 @@ public function selectCollection(string $databaseName, string $collectionName, a
370
399
*/
371
400
public function selectDatabase (string $ databaseName , array $ options = [])
372
401
{
373
- $ options += ['typeMap ' => $ this ->typeMap , 'builderEncoder ' => $ this ->builderEncoder ];
374
-
375
- return new Database ($ this ->manager , $ databaseName , $ options );
402
+ return $ this ->getDatabase ($ databaseName , $ options );
376
403
}
377
404
378
405
/**
0 commit comments