@@ -97,7 +97,8 @@ class MyService
9797}
9898` ` `
9999
100- If you register multiple clients, you can autowire them by name + `Client` suffix :
100+ If you register multiple clients, you can autowire them by using the client name with a `Client` suffix as parameter
101+ name :
101102
102103` ` ` php
103104use MongoDB\B undle\A ttribute\A utowireClient;
@@ -106,6 +107,7 @@ use MongoDB\Client;
106107class MyService
107108{
108109 public function __construct(
110+ // Will autowire the client with the id "second"
109111 private Client $secondClient,
110112 ) {}
111113}
@@ -120,16 +122,16 @@ use MongoDB\Client;
120122class MyService
121123{
122124 public function __construct(
123- #[AutowireClient('second')]
125+ #[AutowireClient('second')]
124126 private Client $client,
125127 ) {}
126128}
127129` ` `
128130
129131# # Database and Collection Usage
130132
131- The client service provides access to databases and collections. You can access a database by calling the `selectDatabase`
132- method, passing the database name and potential options :
133+ The client service provides access to databases and collections. You can access a database by calling the
134+ `selectDatabase` method, passing the database name and potential options :
133135
134136` ` ` php
135137use MongoDB\C lient;
@@ -162,21 +164,9 @@ class MyService
162164}
163165` ` `
164166
165- You can also omit the `database` option if the property name matches the database name.
166- In the following example the database name is `myDatabase`, inferred from the property name :
167-
168- ` ` ` php
169- use MongoDB\B undle\A ttribute\A utowireCollection;
170- use MongoDB\D atabase;
171-
172- class MyService
173- {
174- public function __construct(
175- #[AutowireDatabase]
176- private Database $myDatabase,
177- ) {}
178- }
179- ` ` `
167+ If you don't specify a database name in the attribute, the default database name (specified in the `default_database`
168+ configuration option) will be used. If you did not define a default database, the database name has to be specified in
169+ the attribute.
180170
181171If you have more than one client defined, you can also reference the client :
182172
@@ -248,14 +238,15 @@ class MyService
248238}
249239` ` `
250240
251- By specifiying the `default_database` option in the configuration, you can omit the `database` option in the attribute :
241+ By specifiying the `default_database` option in the configuration, you can omit the `database` option in the
242+ `AutowireCollection` attribute :
252243
253244` ` ` diff
254245mongodb:
255246 clients:
256247 default:
257248 uri: '%env(MONGODB_URI)%'
258- + default_database: 'myDtabase '
249+ + default_database: 'myDatabase '
259250` ` `
260251
261252` ` ` php
0 commit comments