初用webman,查询Mongodb出现异常
这里详细描述问题
用到的数据库是Mongodb,一切配置好后,直接composer require jenssegers/mongodb,然后创建了一个对应的模型,Refund.php,做查询操作的时候,发现用不了where方法,最后直接用find('5cf5d8669dc6d607667ef666'),也是报错
<?php
namespace app\model;
use Jenssegers\Mongodb\Eloquent\Model;
class Refund extends Model
{
protected $connection = 'db_mongodb_order_config';
protected $collection = 'refund';
}
<?php
namespace app\controller;
use app\model\Refund;
use support\Request;
class RefundController
{
public function applyRefund(Request $request): \support\Response
{
$data = Refund::find('63ad43e1d8bfe15ba708342d');
return json(['data' => $data, 'msg' => '', 'code' => 0]);
}
}
ErrorException: Use of "parent" in callables is deprecated in /www/webman/vendor/jenssegers/mongodb/src/Query/Builder.php:900
Stack trace:
#0 [internal function]: support\App::{closure}(8192, 'Use of "parent"...', '/www/webman/ven...', 900)
#1 /www/webman/vendor/jenssegers/mongodb/src/Query/Builder.php(900): call_user_func_array('parent::where', Array)
#2 /www/webman/vendor/illuminate/database/Eloquent/Builder.php(288): Jenssegers\Mongodb\Query\Builder->where('_id', '=', '63ad43e1d8bfe15...')
#3 /www/webman/vendor/illuminate/database/Eloquent/Builder.php(244): Illuminate\Database\Eloquent\Builder->where('_id', '=', '63ad43e1d8bfe15...')
#4 /www/webman/vendor/illuminate/database/Eloquent/Builder.php(434): Illuminate\Database\Eloquent\Builder->whereKey('63ad43e1d8bfe15...')
#5 /www/webman/vendor/illuminate/support/Traits/ForwardsCalls.php(23): Illuminate\Database\Eloquent\Builder->find('63ad43e1d8bfe15...')
#6 /www/webman/vendor/illuminate/database/Eloquent/Model.php(2321): Illuminate\Database\Eloquent\Model->forwardCallTo(Object(Jenssegers\Mongodb\Eloquent\Builder), 'find', Array)
#7 /www/webman/vendor/jenssegers/mongodb/src/Eloquent/Model.php(516): Illuminate\Database\Eloquent\Model->__call('find', Array)
#8 /www/webman/vendor/illuminate/database/Eloquent/Model.php(2333): Jenssegers\Mongodb\Eloquent\Model->__call('find', Array)
#9 /www/webman/app/controller/RefundController.php(12): Illuminate\Database\Eloquent\Model::__callStatic('find', Array)
#10 /www/webman/vendor/workerman/webman-framework/src/App.php(295): app\controller\RefundController->applyRefund(Object(support\Request))
#11 /www/webman/vendor/workerman/webman-framework/src/App.php(122): Webman\App::Webman\{closure}(Object(support\Request))
#12 /www/webman/vendor/workerman/workerman/Connection/TcpConnection.php(646): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(support\Request))
#13 [internal function]: Workerman\Connection\TcpConnection->baseRead(Resource id #312, 2, Resource id #312)
#14 /www/webman/vendor/workerman/workerman/Events/Event.php(193): EventBase->loop()
#15 /www/webman/vendor/workerman/workerman/Worker.php(2467): Workerman\Events\Event->loop()
#16 /www/webman/vendor/workerman/workerman/Worker.php(1578): Workerman\Worker->run()
#17 /www/webman/vendor/workerman/workerman/Worker.php(1420): Workerman\Worker::forkOneWorkerForLinux(Object(Workerman\Worker))
#18 /www/webman/vendor/workerman/workerman/Worker.php(1394): Workerman\Worker::forkWorkersForLinux()
#19 /www/webman/vendor/workerman/workerman/Worker.php(1724): Workerman\Worker::forkWorkers()
#20 /www/webman/vendor/workerman/workerman/Worker.php(1664): Workerman\Worker::monitorWorkersForLinux()
#21 /www/webman/vendor/workerman/workerman/Worker.php(562): Workerman\Worker::monitorWorkers()
#22 /www/webman/vendor/workerman/webman-framework/src/support/App.php(124): Workerman\Worker::runAll()
#23 /www/webman/start.php(4): support\App::run()
#24 {main}
目测jenssegers/mongodb不支持php8.2,php 8.2才发布一个月,很多第三方库不支持,最好等个一年半年再用php8.2
居然跟我用8.2有关?
看到
is deprecated
关键字一般就是php版本高了,或者说某个库不支持当前php版本可以啊老兄
你解决这个问题了嘛
你的mongo是自己用docker搭建的replica集群吗,还是直接用的 阿里云或者mongo云成品
自己在本地整的docker
我记得用tp的orm单点mongo是跑不起来的,你是咋样的架构