reasno/fastmongo
Composer 安装命令:
composer require reasno/fastmongo
包简介
mongodb driver via hyperf/gotask
README 文档
README
reasno/fastmongo is the a coroutine-based mongodb client for Hyperf, powered by hyperf/gotask.
Installation
composer require reasno/fastmongo
- MongoDB extension is required.
- MongoDB > 4.0
- MongoDB PHP library is NOT required.
- Go is NOT required.
Configuration
Just set the environmental variable MONGODB_URI. (Defaults to mongodb://127.0.0.1:27017)
You may also use php bin/hyperf.php vendor:publish reasno/fastmongo to export a configuration.
API List
<?php namespace App\Controller; use Hyperf\GoTask\MongoClient\MongoClient; class IndexController { public function index(MongoClient $client) { $col = $client->my_database->my_col; $col->insertOne(['gender' => 'male', 'age' => 18]); $col->insertMany([['gender' => 'male', 'age' => 20], ['gender' => 'female', 'age' => 18]]); $col->countDocuments(); $col->findOne(['gender' => 'male']); $col->find(['gender' => 'male'], ['skip' => 1, 'limit' => 1]); $col->updateOne(['gender' => 'male'], ['$inc' => ['age' => 1]]); $col->updateMany(['gender' => 'male'], ['$inc' => ['age' => 1]]); $col->replaceOne(['gender' => 'female'], ['gender' => 'female', 'age' => 15]); $col->aggregate([ ['$match' => ['gender' => 'male']], ['$group' => ['_id' => '$gender', 'total' => ['$sum' => '$age']]], ]); $col->deleteOne(['gender' => 'male']); $col->deleteMany(['age' => 15]); $col->drop(); // if there is a command not yet supported, use runCommand or runCommandCursor. $client->my_database->runCommand(['ping' => 1]); return $client->my_database->runCommandCursor(['listCollections' => 1]); } }
Background
This package makes use of hyperf/gotask to achieve coroutine.
In hyperf/gotask v2.1.0 a new mongodb package is added. Normally GoTask requires you to do some coding in Go. However this approach demands some proficiency in Go, which can be prohibitive. reasno/fastmongo is a prebuilt version of the newly added mongodb package. It vendors the Go binary for you so you don't have to compile your own.
This package only exposes a very simple yet optimized configuration interface. Should more customization be needed, checkout out the original hyperf/gotask.
Please do not turn on
hyperf/gotaskand this package at the same time.
Future Scope
- More mongodb commands can be added. Please feel free to create issues or submit your PRs to
hyperf/gotask.
reasno/fastmongo 适用场景与选型建议
reasno/fastmongo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 75.13k 次下载、GitHub Stars 达 89, 最近一次更新时间为 2020 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「hyperf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 reasno/fastmongo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 reasno/fastmongo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 reasno/fastmongo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 75.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 90
- 点击次数: 16
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-01