hualaoshuan / swoft2-mongodb
extension for Swoft2-MongoDB
v1.0.0
2020-04-26 12:49 UTC
Requires
- php: >=7.0
- ext-mongodb: ^1.7
- swoft/framework: ^2.0
Requires (Dev)
- swoft/db: ^2.0
- swoft/framework: ^2.0
This package is auto-updated.
Last update: 2025-02-27 13:32:03 UTC
README
composer require hualaoshuan/swoft2-mongodb
使用方法
- 在对应的
config/dev
和config/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' ];
- 在 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'; } }