我尝试将Laravel 5.4.36与mongodb连接
我的mongo数据库版本v3.4.16
已安装
composer require jenssegers/mongodb:3.2.0
jenssegers/mongodb-session
jenssegers/mongodb-sentry
config / app.php
Jenssegers\Mongodb\MongodbServiceProvider::class,
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Mymodel extends Eloquent
{
protected $connection = 'mongodb';
protected $collection = 'addresses';
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Mymodel;
use Illuminate\Support\Facades\DB;
class ConnectmongoController extends Controller
{
public function index()
{
$node = Mymodel::all();
echo "hi";
}
}
'mongodb' => [
'driver' => 'mongodb',
'host' => 'localhost',
'port' => 27017,
'database' => 'mydb',
'username' => 'usrename',
'password' => 'password',
'options' => [
'database' => 'admin' // sets the authentication database required by mongo 3
]
],
虽然我调用控制器功能 它显示错误
1/1)InvalidArgumentException 不支持的驱动程序[mongodb]
在ConnectionFactory.php第286行中
我找不到我在哪里犯错了/没有任何步骤。
答案 0 :(得分:0)
MongoDB扩展^ 1.5不支持mongoDB 2.6
https://docs.mongodb.com/ecosystem/drivers/php/#mongodb-compatibility