PHP code example of pimenvibritania / yii3-mongodb
1. Go to this page and download the library: Download pimenvibritania/yii3-mongodb library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Pimenvibritania\Yii3Mongodb\Mongo as MongoClient;
class Example {
public function __construct(private MongoClient $mongoClient){}
public function getAll(): array
{
return $this->collection()->find(
[],
[
'sort' => [
'createdAt' => -1,
]
]
)->toArray();
}
private function collection(): \MongoDB\Collection
{
return $this->mongoClient->getCollection("your_collection");
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.