hualaoshuan / swoft2-mongodb
extension for Swoft2-MongoDB
Installs: 460
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/hualaoshuan/swoft2-mongodb
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-10-27 14:53:35 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'; } }