yumufeng / hyperf-mongodb Goto Github PK
View Code? Open in Web Editor NEW基于hyperf的mongodb连接池组件,暂不支持协程
基于hyperf的mongodb连接池组件,暂不支持协程
我这边有mongo多库的配置需求,请问可以在hyperf里配置多个mongodb吗?如果可以的话应该怎么配置?
使用效果怎么样啊。
我的 hyperf/utils 版本为 v2.1.0,安装的时候提示版本过高,我试过降级都安装不了,求给个解决办法,谢谢
因为一些复杂的分页条件(需要用到$in, $sort,$gte),fetchPagination并不满足我的条件。
我就用command方法操作。
问题:第一页没有问题 条件如下:
[{"$sort":{"_id":-1}},{"$match":{"coupon_id":493,"user_id":{"$in":[1]}}},{"$limit":10},{"$skip":0}]
当我第二页的时候,无法返回数据
[{"$sort":{"_id":-1}},{"$match":{"coupon_id":493,"user_id":{"$in":[1]}}},{"$limit":10},{"$skip":10}]
$username = $this->config['username'];
$password = $this->config['password'];
if (!empty($username) && !empty($password)) {
$uri = sprintf(
'mongodb://%s:%s@%s:%d/%s',
$username,
$password,
$this->config['host'],
$this->config['port'],
$this->config['db']
);
} else {
$uri = sprintf(
'mongodb://%s:%d/%s',
$this->config['host'],
$this->config['port'],
$this->config['db']
);
}
$urlOptions = [];
//数据集
$replica = isset($this->config['replica']) ? $this->config['replica'] : null;
if ($replica) {
$urlOptions['replicaSet'] = $replica;
}
$this->connection = new Manager($uri, $urlOptions);
$Uri 拼接上db后会链接出错,如果配置文件里面的db 填了admin, 但要查询的数据库别的,这里就出问题了。
同样的配置文件,在其它框架里面都可以。。。这里应该可以优化下
你好
不預先配置 config 如何在運行時期動態指定 mongodb 的連結IP、port、database name呢?
Xuan
public function command(string $namespace, array $filter = [])
{
try {
$command = new Command([
'aggregate' => $namespace,
'pipeline' => $filter,
'cursor' => new \stdClass()
]);
$cursor = $this->connection->executeCommand($this->config['db'], $command);
$count = $cursor->toArray()[0];
} catch (\Exception $e) {
$count = false;
throw new MongoDBException($e->getFile() . $e->getLine() . $e->getMessage());
} finally {
$this->pool->release($this);
return $count;
}
}
$count = $cursor->toArray()[0];
这个转数组后取[0]是有什么原因吗,这样会导致获取的数据不是一个列表
看起来只是创建了一个协程版的连接池,连接池里连接的创建/查询等io都运行在协程里,这样会阻塞协程调度吧?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.