hualaoshuan/swoft2-mongodb

extension for Swoft2-MongoDB

v1.0.0 2020-04-26 12:49 UTC

This package is auto-updated.

Last update: 2021-12-27 06:51:47 UTC


README

composer require hualaoshuan/swoft2-mongodb

使用方法

  1. 在对应的config/devconfig/pro目录下新建mongo.php配置文件
<?php

return [
    'appName' => 'mongodb-swoole-connection',
    'userName' => 'root',
    'password' => 'asdf',
    'host' => '192.168.60.169',
    'port' => 27017,
    'dbName'=> 'test',
    'authMechanism' => 'SCRAM-SHA-256'
];
  1. 在 Controller 里调用
<?php

namespace App\Http\Controller;

use Hualaoshuan\Mongodb\Mongo;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
use Swoft\Http\Server\Annotation\Mapping\RequestMethod;

/**
 * Class testController
 * @Controller(prefix="/test")
 */
class TestController{
    
    /**
     * @RequestMapping(route="/test",method={RequestMethod::GET})
     */
    public function test(){
        $result = Mongo::fetchAll('user', ['id' => 1], ['id']);
        var_dump($result);
        return 'OK';
    }
}