aodto / mongoqb
Mongo查询构建器
1.3.1
2015-05-25 08:10 UTC
Requires
- php: >=5.3.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-14 17:42:47 UTC
README
通过Packagist和Composer安装
将以下内容添加到您的composer.json文件中
{ "require": { "aodto/mongoqb": "*" } }
然后运行
composer install
通过Git安装
git clone git://git@github.com:aodto/MongoQB
下载zip/tarball
下载最新版本
(注意,zip/tarball不会包含任何单元测试或composer文件)
单元测试
该库目前有100%的单元测试覆盖率。要运行单元测试套件,请确保您已在本地上安装并运行MongoDB,且没有认证,默认端口为- 27017。
然后运行
composer update --dev
cd vendor/aodto/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');
如果您发现任何错误,请在问题跟踪器中提交报告
如果您觉得这个软件有用,请考虑捐赠,谢谢=]