giginc/cakephp5-driver-mongodb
Composer 安装命令:
composer require giginc/cakephp5-driver-mongodb
包简介
MongoDB datasource driver for CakePHP 5 (modern successor to giginc/mongodb).
README 文档
README
MongoDB datasource driver for CakePHP 5 — the modern successor to giginc/mongodb.
Targets PHP 8.1+, CakePHP 5, and mongodb/mongodb 2.x. The public API follows
CakePHP 5 conventions (fluent query builder, marshaller, entities) and does
not preserve the array-based call style of the v3 plugin.
Status: scaffold / work in progress. Connection + Driver + Table base + Marshaller/Entity conversion are in scope. Associations, behaviors, and SSH tunnelling are deferred to a later release.
Requirements
- PHP
^8.1 ext-mongodbmongodb/mongodb^2.0cakephp/cakephp^5.0
Installation
composer require giginc/cakephp5-driver-mongodb
Then load the plugin (optional — the package only contributes a Connection/ Driver/Table base, so loading is not strictly required):
bin/cake plugin load Giginc/Mongodb
Configuration
In config/app.php:
'Datasources' => [ 'mongo' => [ 'className' => \Giginc\Mongodb\Database\Connection::class, 'driver' => \Giginc\Mongodb\Database\Driver\Mongodb::class, 'host' => 'localhost', 'port' => 27017, 'database' => 'my_database', 'username' => '', 'password' => '', // or a full DSN that wins over host/port/auth: // 'uri' => 'mongodb://user:pass@host:27017/my_database?authSource=admin', ], ],
Usage
// src/Model/Table/UsersTable.php <?php declare(strict_types=1); namespace App\Model\Table; use Giginc\Mongodb\ORM\Table; class UsersTable extends Table { public function initialize(array $config): void { parent::initialize($config); $this->setConnection(ConnectionManager::get('mongo')); } protected ?string $table = 'users'; }
use App\Model\Table\TestsTable; $users = new UsersTable(); // Fluent queries $list = $users->find() ->where(['status' => 'active']) ->order(['created' => 'DESC']) ->limit(10) ->toArray(); // Single row by _id $user = $users->get($id); // Create / update $entity = $users->newEntity(['name' => 'alice', 'status' => 'active']); $users->save($entity); // Delete $one = $users->find() ->first(); $users->delete($one);
Migration guide (from giginc/mongodb)
Namespace map
Old (giginc/mongodb) |
New |
|---|---|
Giginc\Mongodb\Database\Connection |
Giginc\Mongodb\Database\Connection |
Giginc\Mongodb\Database\Driver\Mongodb |
Giginc\Mongodb\Database\Driver\Mongodb |
Giginc\Mongodb\ORM\Table |
Giginc\Mongodb\ORM\Table |
Giginc\Mongodb\ORM\Document |
Giginc\Mongodb\ORM\Document |
Giginc\Mongodb\ORM\ResultSet |
Cake\Datasource\ResultSetDecorator (Cake 標準を直接利用) |
Giginc\Mongodb\ORM\MongoFinder / MongoQuery |
Giginc\Mongodb\ORM\Query (fluent, new design) |
API changes (non-exhaustive)
find('all', ['conditions' => [...], 'fields' => [...], 'limit' => 10])→find()->where([...])->select([...])->limit(10)->toArray()The legacy array form is intentionally not supported.get($id)now throwsCake\Datasource\Exception\RecordNotFoundException(was:InvalidPrimaryKeyException).- The base
Tableno longer extendsCake\ORM\Table. SQL-specific helpers (associations, behaviors, SQL query objects) are unavailable in this scope. lastInsertId(),transactional(),disableConstraints()are no-ops — MongoDB semantics differ and this driver does not fake them.- SSH tunnelling (
ssh_host,ssh_user, etc. in legacy config) is removed in this release. Use your own tunnel if needed.
Development
# start a local MongoDB for tests docker compose -f docker-compose.test.yml up -d composer install composer test composer cs-check composer stan
Integration tests read MONGODB_URI / MONGODB_DATABASE from env, defaulting
to mongodb://127.0.0.1:27017 and cakephp5_mongodb_driver_test.
License
MIT — see LICENSE.
giginc/cakephp5-driver-mongodb 适用场景与选型建议
giginc/cakephp5-driver-mongodb 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 171 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「orm」 「mongodb」 「plugin」 「cakephp」 「driver」 「datasource」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 giginc/cakephp5-driver-mongodb 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 giginc/cakephp5-driver-mongodb 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 giginc/cakephp5-driver-mongodb 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Generates Symfony2 documents, forms and CRUD
Kinikit - PHP Application development framework MVC component
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
A package to allow laravel/passport use with mongodb/laravel-mongodb
MongoDB Adapter to be used with Laminas Paginator
统计信息
- 总下载量: 171
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 46
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-18