jumplead / mongoqb
Mongo Query Builder
1.3.4
2018-07-23 09:18 UTC
Requires
- php: >=5.3.0
Requires (Dev)
README
通过 Packagist 和 Composer 安装
将以下内容添加到您的 composer.json 文件中
{ "require": { "jumplead/mongoqb": "*" } }
然后运行
composer install
通过 Git 安装
git clone git://git@github.com:jumplead/MongoQB
下载 zip/tarball
下载最新版本
(注意,zip/tarball 不会包含任何单元测试或 composer 文件)
单元测试
该库目前有 100% 的单元测试覆盖率。要运行单元测试套件,请确保您已在本地上安装并运行 MongoDB,无身份验证,默认端口为 27017。
然后运行
composer update --dev
cd vendor/jumplead/mongoqb
phpunit -c tests/phpunit.xml
示例用法
连接到数据库
$qb = \MongoQB\Builder(array( 'dsn' => 'mongodb://user:pass@localhost:27017/databaseName' );
插入一个文档
$qb->insert('collectionName', [ 'name' => 'Alex', 'age' => 22, 'likes' => ['whisky', 'gin'] ]);
更新单个文档
$qb ->where(['name' => 'Alex']) ->set([ 'country' => 'UK', 'job' => 'Developer' ]) ->push('likes', ['PHP', 'coffee']) ->update('collectionName');
删除单个文档
$qb ->where(['name' => 'Alex']) ->delete('collectionName');
搜索匹配的文档
$results = $qb ->whereGt('age', 21) ->whereIn('likes', ['whisky']) ->where('country', 'UK') ->get('collectionName');
如果您发现任何错误,请在 问题追踪器 中提交报告