使用mongodb连接线上报错

初试

问题描述

这里详细描述问题
使用扩展为"jenssegers/mongodb": "3.8.0",线上的mongodb版本("version": "7.0.8")
现在使用navicat连接线上的mongodb地址是可以连接成功的,
但是代码在database里面配置在下面(host本应该是连接的线上地址,但是为了规避所以先写成了本地的),
然后在新增数据的时候一致报错( Authentication failed),尝试在配置中options中的参数,但是也是没有效果,请教一个各位大佬,要怎么去解决这个问题

程序代码

// 基础配置信息如下
        'mongodb' => [
            'driver'   => 'mongodb',
            'host'     => '127.0.0.1',
            'port'     =>  27017,
            'database' => 'bbs',
            'username' => 'bbs',
            'password' => 'e8fSktkKzX3cFKBt',
            'options' => [
//                'authSource' => 'bbs',
//                'ssl' => false,
                'appname' => 'homestead'
            ],
        ],
// 操作代码
   public function __construct()
    {
        $this->mongoSql = Db::connection('mongodb')->collection('requestip_list');
    }

    /**
     * 新增请求ip记录信息
     *
     * @param  array $arr  数据信息
     * @return void
     */
    public function siginMongoInfo(array $arr)
    {
        $arr['update_time']  = Carbon::now()->format('Y-m-d H:i:s');
        $arr['create_time']  = Carbon::now()->format('Y-m-d H:i:s');
//        Db::connection('mongodb')->collection('requestip_list')->insert($arr);
        $this->mongoSql->insert($arr);
    }

报错信息

MongoDB\Driver\Exception\AuthenticationException: Authentication failed. in D:\phpstudy_pro\WWW\bbs-api\vendor\mongodb\mongodb\src\Operation\InsertMany.php:163<br />
Stack trace:<br />
#0 D:\phpstudy_pro\WWW\bbs-api\vendor\mongodb\mongodb\src\Operation\InsertMany.php(163): MongoDB\Driver\Server->executeBulkWrite()<br />
#1 D:\phpstudy_pro\WWW\bbs-api\vendor\mongodb\mongodb\src\Collection.php(908): MongoDB\Operation\InsertMany->execute()<br />
#2 [internal function]: MongoDB\Collection->insertMany()<br />
#3 D:\phpstudy_pro\WWW\bbs-api\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Collection.php(42): call_user_func_array()<br />
#4 D:\phpstudy_pro\WWW\bbs-api\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Query\Builder.php(570): Jenssegers\Mongodb\Collection->__call()<br />
#5 D:\phpstudy_pro\WWW\bbs-api\app\service\RequestipListService.php(39): Jenssegers\Mongodb\Query\Builder->insert()<br />
208 0 0
0个回答

×
🔝