think-orm在webman2.1使用mongo數(shù)據(jù)庫出現(xiàn)TypeError: think\db\connector\Mongo::query()
TypeError: think\db\connector\Mongo::query(): Argument #1 ($query) must be of type MongoDB\Driver\Query, string given, called in /www/wwwroot/shu_cang/vendor/webman/think-orm/src/DbManager.php on line 54 and defined in /www/wwwroot/shu_cang/vendor/topthink/think-orm/src/db/connector/Mongo.php:298
Stack trace:
#0 /www/wwwroot/shu_cang/vendor/webman/think-orm/src/DbManager.php(54): think\db\connector\Mongo->query()
#1 /www/wwwroot/shu_cang/vendor/workerman/coroutine/src/Pool.php(328): Webman\ThinkOrm\DbManager->W(wǎng)ebman\ThinkOrm\{closure}()
#2 /www/wwwroot/shu_cang/vendor/workerman/coroutine/src/Pool.php(312): Workerman\Coroutine\Pool->trySendHeartbeat()
#3 /www/wwwroot/shu_cang/vendor/workerman/coroutine/src/Pool.php(132): Workerman\Coroutine\Pool->checkConnections()
#4 /www/wwwroot/shu_cang/vendor/w
Workerman/5.1.1 PHP/8.2.27 (Jit off) Linux/6.1.0-31-amd64
先修改代碼使用,等后續(xù)更新webman/think-orm。
$pool->setHeartbeatChecker(function ($connection) {
if (in_array($connection->getDriverName(), ['mysql', 'pgsql', 'sqlite', 'sqlsrv'])) {
$connection->select('select 1');
} elseif ($connection->getDriverName() === 'mongodb') {
$connection->command(['ping' => 1]);
}
});