1. Go to this page and download the library: Download bvtvd/mongo-db 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/ */
bvtvd / mongo-db example snippets
declare(strict_types=1);
namespace TmgAddon\WebQySession\Model;
use Hyperf\Task\Annotation\Task;
use Phper666\MongoDb\MongoDb;
class Test extends MongoDb
{
public $collectionName = 'test';
public static function collectionName()
{
return 'test';
}
/**
* @Task(timeout=20)
* @return array
*/
public function getMethod($method, ...$params)
{
return $this->{$method}(...$params);
}
}
// 调用,实际跟原有的findOne调用的参数是一致的,只不过第一个参数时申明要调用申明方法
$data = make(Test::class)->getMethod('findOne', ['name' => '1'], ['projection' => ['name' => 1]]);