@@ -168,7 +168,7 @@ public function __debugInfo(): array
168168 */
169169 public function __get (string $ databaseName ): Database
170170 {
171- return $ this ->selectDatabase ($ databaseName );
171+ return $ this ->getDatabase ($ databaseName );
172172 }
173173
174174 /**
@@ -230,6 +230,37 @@ public function dropDatabase(string $databaseName, array $options = []): void
230230 $ operation ->execute ($ server );
231231 }
232232
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+
233264 /**
234265 * Return the Manager.
235266 */
@@ -329,9 +360,7 @@ final public function removeSubscriber(Subscriber $subscriber): void
329360 */
330361 public function selectCollection (string $ databaseName , string $ collectionName , array $ options = []): Collection
331362 {
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 );
335364 }
336365
337366 /**
@@ -344,9 +373,7 @@ public function selectCollection(string $databaseName, string $collectionName, a
344373 */
345374 public function selectDatabase (string $ databaseName , array $ options = []): Database
346375 {
347- $ options += ['typeMap ' => $ this ->typeMap , 'builderEncoder ' => $ this ->builderEncoder ];
348-
349- return new Database ($ this ->manager , $ databaseName , $ options );
376+ return $ this ->getDatabase ($ databaseName , $ options );
350377 }
351378
352379 /**
0 commit comments