All Projects → yumufeng → hyperf-mongodb

yumufeng / hyperf-mongodb

Licence: other
基于hyperf的mongodb连接池组件,暂不支持协程

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to hyperf-mongodb

SimpleObjectPool
Simple thread-safe object pool in Objective-C
Stars: ✭ 13 (-23.53%)
Mutual labels:  pool
cryptonote-aeon-pool
AEON coin mining pool
Stars: ✭ 15 (-11.76%)
Mutual labels:  pool
cloudnative-hyperf
A cloud native hyperf skeleton, featuring kubernetes
Stars: ✭ 36 (+111.76%)
Mutual labels:  hyperf
agroal
The natural database connection pool
Stars: ✭ 92 (+441.18%)
Mutual labels:  pool
arikado gridcoin pool
Simple gridcoin pool
Stars: ✭ 20 (+17.65%)
Mutual labels:  pool
charnapool
High performance Node.js (with native C addons) mining pool for Cryptonote based coins, optimized for Charnacoin.
Stars: ✭ 25 (+47.06%)
Mutual labels:  pool
gohive
🐝 A Highly Performant and easy to use goroutine pool for Go
Stars: ✭ 41 (+141.18%)
Mutual labels:  pool
ferryd
Fast, safe and reliable transit for the delivery of software updates to users.
Stars: ✭ 43 (+152.94%)
Mutual labels:  pool
swoole-postgresql-doctrine-driver
🔌 A Doctrine DBAL Driver implementation on top of Swoole Coroutine PostgreSQL client
Stars: ✭ 15 (-11.76%)
Mutual labels:  pool
nodejs-poolController
An application to control pool equipment from various manufacturers.
Stars: ✭ 162 (+852.94%)
Mutual labels:  pool
dotnet-design-patterns-samples
The samples of .NET design patterns
Stars: ✭ 25 (+47.06%)
Mutual labels:  pool
HiFramework.Unity
Based on component to manage project's core logic and module used in unity3d
Stars: ✭ 22 (+29.41%)
Mutual labels:  pool
simple-pool
#NVJOB Simple Pool. Pool for optimizing object loading. Unity Asset.
Stars: ✭ 16 (-5.88%)
Mutual labels:  pool
hyperf-v2-demo
Hyperf Demo(easywechat,chat)
Stars: ✭ 19 (+11.76%)
Mutual labels:  hyperf
pooled redis
Simple way to access redis connections without global variables.
Stars: ✭ 18 (+5.88%)
Mutual labels:  pool
ethersocial-pool
Open EthersocialNetwork Mining Pool based off the sammy007's open-ethereum-pool
Stars: ✭ 19 (+11.76%)
Mutual labels:  pool
not-only-mining-pool
new generation general mining pool in go
Stars: ✭ 31 (+82.35%)
Mutual labels:  pool
alarm-dog
哮天犬是一个通用的统一告警平台,提供配置化、流程化、标准化的能力,支持多种告警通知渠道,支持告警收敛、过滤、升级、工作流、自动恢复等功能,实现统一输入、不同输出。可以对接Grafana、阿里云Arms、实时计算等监控能力,各业务也可以直接在代码中埋点上报告警,也可以定制化开发,实现监控告警全场景覆盖。https://tal-tech.github.io/alarm-dog-docs
Stars: ✭ 165 (+870.59%)
Mutual labels:  hyperf
pool
Connection pool for Go's grpc client with supports connection reuse.
Stars: ✭ 105 (+517.65%)
Mutual labels:  pool
fastthreadpool
An efficient and lightweight thread pool
Stars: ✭ 27 (+58.82%)
Mutual labels:  pool

hyperf mongodb pool

composer require yumufeng/hyperf-mongodb

config

在/config/autoload目录里面创建文件 mongodb.php 添加以下内容

return [
    'default' => [
             'username' => env('MONGODB_USERNAME', ''),
             'password' => env('MONGODB_PASSWORD', ''),
             'host' => env('MONGODB_HOST', '127.0.0.1'),
             'port' => env('MONGODB_PORT', 27017),
             'db' => env('MONGODB_DB', 'test'),
             'authMechanism' => 'SCRAM-SHA-256',
             //设置复制集,没有不设置
             //'replica' => 'rs0',
            'pool' => [
                'min_connections' => 3,
                'max_connections' => 1000,
                'connect_timeout' => 10.0,
                'wait_timeout' => 3.0,
                'heartbeat' => -1,
                'max_idle_time' => (float) env('MONGODB_MAX_IDLE_TIME', 60),
            ],
    ],
];

使用案例

使用注解,自动加载 \Hyperf\Mongodb\MongoDb

/**
 * @Inject()
 * @var MongoDb
*/
 protected $mongoDbClient;

tips:

查询的值,是严格区分类型,string、int类型的哦

新增

单个添加

$insert = [
            'account' => '',
            'password' => ''
];
$this->$mongoDbClient->insert('fans',$insert);

批量添加

$insert = [
            [
                'account' => '',
                'password' => ''
            ],
            [
                'account' => '',
                'password' => ''
            ]
];
$this->$mongoDbClient->insertAll('fans',$insert);

查询

$where = ['account'=>'1112313423'];
$result = $this->$mongoDbClient->fetchAll('fans', $where);

分页查询

$list = $this->$mongoDbClient->fetchPagination('article', 10, 0, ['author' => $author]);

更新

$where = ['account'=>'1112313423'];
$updateData = [];

$this->$mongoDbClient->updateColumn('fans', $where,$updateData); // 只更新数据满足$where的行的列信息中在$newObject中出现过的字段
$this->$mongoDbClient->updateRow('fans',$where,$updateData);// 更新数据满足$where的行的信息成$newObject

删除

$where = ['account'=>'1112313423'];
$all = true; // 为false只删除匹配的一条,true删除多条
$this->$mongoDbClient->delete('fans',$where,$all);

count统计

$filter = ['isGroup' => "0", 'wechat' => '15584044700'];
$count = $this->$mongoDbClient->count('fans', $filter);

Command,执行更复杂的mongo命令

sqlmongodb 关系对比图

SQL MongoDb
WHERE $match (match里面可以用and,or,以及逻辑判断,但是好像不能用where)
GROUP BY $group
HAVING $match
SELECT $project
ORDER BY $sort
LIMIT $limit
SUM() $sum
COUNT() $sum
$pipeline= [
            [
                '$match' => $where
            ], [
                '$group' => [
                    '_id' => [],
                    'groupCount' => [
                        '$sum' => '$groupCount'
                    ]
                ]
            ], [
                '$project' => [
                    'groupCount' => '$groupCount',
                    '_id' => 0
                ]
            ]
];

$count = $this->$mongoDbClient->command('fans', $pipeline);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].