Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pimenvibritania/yii3-mongodb
Mongodb Service & Depedency Injection for Yii3
https://github.com/pimenvibritania/yii3-mongodb
mongodb php yii yii3
Last synced: 2 days ago
JSON representation
Mongodb Service & Depedency Injection for Yii3
- Host: GitHub
- URL: https://github.com/pimenvibritania/yii3-mongodb
- Owner: pimenvibritania
- Created: 2022-06-02T08:19:03.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-06-02T14:31:13.000Z (over 2 years ago)
- Last Synced: 2024-12-06T09:08:48.553Z (20 days ago)
- Topics: mongodb, php, yii, yii3
- Language: PHP
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Yii3 Mongodb
MongoDB Service for Yii3 API.
## Requirement
- PHP MongoDB extension/driver already installed
## Installation
```shell
composer require composer require pimenvibritania/yii3-mongodb
```
## Configuration
Add this to your `DI` configuration:
```php
[
'class' => Mongo::class,
'__construct()' => [
$params['mongodb/mongodb']['uri'],
$params['mongodb/mongodb']['host'],
$params['mongodb/mongodb']['username'],
$params['mongodb/mongodb']['password'],
$params['mongodb/mongodb']['ssl'],
$params['mongodb/mongodb']['database'],
$params['mongodb/mongodb']['retryWrites'],
$params['mongodb/mongodb']['tlsAllowInvalidCertificates'],
$params['mongodb/mongodb']['collections'],
]
],
];
```
Add this to your `params-local.php`
```php
[
"uri" => $_ENV["MONGODB_BASE_URL"],
"host" => $_ENV["MONGODB_HOST"],
"username" => $_ENV["MONGODB_USERNAME"],
"password" => $_ENV["MONGODB_PASSWORD"],
"database" => $_ENV["MONGODB_DATABASE"],
"ssl" => "@root/rds-combined-ca-bundle.pem", //SSL configuration path if needed
"tlsAllowInvalidCertificates" => true,
"retryWrites" => false,
"collections" => [
"yourCollectionAlias" => "yourCollection",
],
],
];```
Then add this key to your `.env````dotenv
MONGODB_BASE_URL=
MONGODB_HOST=
MONGODB_USERNAME=
MONGODB_PASSWORD=
MONGODB_DATABASE=
```## Usages
example:
```php
collection()->find(
[],
[
'sort' => [
'createdAt' => -1,
]
]
)->toArray();
}
private function collection(): \MongoDB\Collection
{
return $this->mongoClient->getCollection("your_collection");
}
}
```## Notes
If you are using AWS `DocumentDB` or using SSL/TLS connection, download this [certificates](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html#:~:text=RDS%20Proxy.-,Certificate%20bundles%20for%20AWS%20Regions,-To%20get%20a) based on your region and put on your project directory (root dir is reccomended)