mongodb 按照文档来配置报错 是没有获取配置文件?
return [
'default'=>'mongodb',
'connections'=>[
'mongodb' => [
[
'driver' => 'mongodb',
'host' => '127.0.0.1',
'port' => 27017,
'database' => 'test',
'username' => null,
'password' => null,
'options' => [
// here you can pass more settings to the Mongo Driver Manager
// see https://www.php.net/manual/en/mongodb-driver-manager.construct.php under "Uri Options" for a list of complete parameters that you can use
'appname' => 'homestead'
],
],
]
]
];
<?php
namespace app\controller;
use support\Db;
class TestController
{
public function test()
{
Db::connection('mongodb')->collection('test')->insert([1,2,3]);
return json(Db::connection('mongodb')->collection('test')->get());
}
}
ErrorException: Undefined index: host in
D:\project\webman_skeleton\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Connection.php:204<br />
Stack trace:<br />
#0 D:\project\webman_skeleton\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Connection.php(204): support\App::{closure}(8, 'Undefined index...', 'D:\\project\\webm...', 204, Array)<br />
#1 D:\project\webman_skeleton\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Connection.php(227): Jenssegers\Mongodb\Connection->getHostDsn(Array)<br />
#2 D:\project\webman_skeleton\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Connection.php(33): Jenssegers\Mongodb\Connection->getDsn(Array)<br />
#3 D:\project\webman_skeleton\vendor\workerman\webman-framework\src\support\bootstrap\LaravelDb.php(61): Jenssegers\Mongodb\Connection->__construct(Array)<br />
#4 [internal function]: support\bootstrap\LaravelDb::support\bootstrap\{closure}(Array, 'mongodb')<br />
#5 D:\project\webman_skeleton\vendor\illuminate\database\DatabaseManager.php(130): call_user_func(Object(Closure), Array, 'mongodb')<br />
#6 D:\project\webman_skeleton\vendor\illuminate\database\DatabaseManager.php(95): Illuminate\Database\DatabaseManager->makeConnection('mongodb')<br />
#7 D:\project\webman_skeleton\vendor\illuminate\database\Capsule\Manager.php(109): Illuminate\Database\DatabaseManager->connection('mongodb')<br />
#8 D:\project\webman_skeleton\vendor\illuminate\database\Capsule\Manager.php(74): Illuminate\Database\Capsule\Manager->getConnection('mongodb')<br />
#9 D:\project\webman_skeleton\app\controller\TestController.php(11): Illuminate\Database\Capsule\Manager::connection('mongodb')<br />
#10 D:\project\webman_skeleton\vendor\workerman\webman-framework\src\App.php(325): app\controller\TestController->mongodb(Object(support\Request))<br />
#11 D:\project\webman_skeleton\vendor\workerman\webman-framework\src\App.php(168): Webman\App::Webman\{closure}(Object(support\Request))<br />
#12 D:\project\webman_skeleton\vendor\workerman\workerman\Connection\TcpConnection.php(646): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(support\Request))<br />
#13 D:\project\webman_skeleton\vendor\workerman\workerman\Events\Select.php(311): Workerman\Connection\TcpConnection->baseRead(Resource id #167)<br />
#14 D:\project\webman_skeleton\vendor\workerman\workerman\Worker.php(1485): Workerman\Events\Select->loop()<br />
#15 D:\project\webman_skeleton\vendor\workerman\workerman\Worker.php(1402): Workerman\Worker::forkWorkersForWindows()<br />
#16 D:\project\webman_skeleton\vendor\workerman\workerman\Worker.php(560): Workerman\Worker::forkWorkers()<br />
#17 D:\project\webman_skeleton\vendor\workerman\webman-framework\src\support\App.php(131): Workerman\Worker::runAll()<br />
#18 D:\project\webman_skeleton\start.php(4): support\App::run()<br />
#19 {main}
按照文档配置啊,你这个明显多了一层
Package jenssegers/mongodb is abandoned, you should avoid using it. Use mongodb/laravel-mongodb instead.
Package yzalis/identicon is abandoned, you should avoid using it. No replacement was suggested.