@@ -97,7 +97,8 @@ class MyService
97
97
}
98
98
` ` `
99
99
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 :
101
102
102
103
` ` ` php
103
104
use MongoDB\B undle\A ttribute\A utowireClient;
@@ -106,6 +107,7 @@ use MongoDB\Client;
106
107
class MyService
107
108
{
108
109
public function __construct(
110
+ // Will autowire the client with the id "second"
109
111
private Client $secondClient,
110
112
) {}
111
113
}
@@ -120,16 +122,16 @@ use MongoDB\Client;
120
122
class MyService
121
123
{
122
124
public function __construct(
123
- #[AutowireClient('second')]
125
+ #[AutowireClient('second')]
124
126
private Client $client,
125
127
) {}
126
128
}
127
129
` ` `
128
130
129
131
# # Database and Collection Usage
130
132
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 :
133
135
134
136
` ` ` php
135
137
use MongoDB\C lient;
@@ -162,21 +164,9 @@ class MyService
162
164
}
163
165
` ` `
164
166
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.
180
170
181
171
If you have more than one client defined, you can also reference the client :
182
172
@@ -248,14 +238,15 @@ class MyService
248
238
}
249
239
` ` `
250
240
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 :
252
243
253
244
` ` ` diff
254
245
mongodb:
255
246
clients:
256
247
default:
257
248
uri: '%env(MONGODB_URI)%'
258
- + default_database: 'myDtabase '
249
+ + default_database: 'myDatabase '
259
250
` ` `
260
251
261
252
` ` ` php
0 commit comments