Skip to content

Fix documentation #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ mongodb:
clients:
default:
uri: '%env(MONGODB_URI)%'
default_database: #...
uriOptions: #...
driverOptions: #...
```
Expand Down Expand Up @@ -146,7 +147,7 @@ class MyService
}
```

An alternative to this is using the `AutowireDatabase` attribute, referencing the database name:
An alternative to this is using the `#[AutowireDatabase]` attribute, referencing the database name:

```php
use MongoDB\Bundle\Attribute\AutowireDatabase;
Expand All @@ -166,13 +167,13 @@ In the following example the database name is `myDatabase`, inferred from the pr

```php
use MongoDB\Bundle\Attribute\AutowireCollection;
use MongoDB\Collection;
use MongoDB\Database;

class MyService
{
public function __construct(
#[AutowireCollection()]
private Collection $myDatabase,
#[AutowireDatabase]
private Database $myDatabase,
) {}
}
```
Expand All @@ -193,7 +194,7 @@ class MyService
```

To inject a collection, you can either call the `selectCollection` method on a `Client` or `Database` instance.
For convenience, the `AutowireCollection` attribute provides a quicker alternative:
For convenience, the `#[AutowireCollection]` attribute provides a quicker alternative:

```php
use MongoDB\Bundle\Attribute\AutowireCollection;
Expand Down Expand Up @@ -230,6 +231,7 @@ class MyService
```

If you have more than one client defined, you can also reference the client:

```php
use MongoDB\Bundle\Attribute\AutowireCollection;
use MongoDB\Collection;
Expand All @@ -245,3 +247,26 @@ class MyService
) {}
}
```

By specifiying the `default_database` option in the configuration, you can omit the `database` option in the attribute:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which attribute?


```diff
mongodb:
clients:
default:
uri: '%env(MONGODB_URI)%'
+ default_database: 'myDtabase'
```

```php
use MongoDB\Bundle\Attribute\AutowireCollection;
use MongoDB\Collection;

class MyService
{
public function __construct(
#[AutowireCollection]
private Collection $myCollection,
) {}
}
```