本文介绍了将Laravel Jenssegers连接到MongoDB Atlas集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从Mongodb Atlas开始,我尝试将laravel/jenssegers项目连接到群集,并配置conf/database
I'am starting with Mongodb atlas and i trying to connect my laravel/jenssegers project to the cluster i config my conf/database
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST'),
'port' => env('DB_PORT', '27017'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'options' => [
'database' => 'admin' // sets the authentication database required by mongo 3
]
],
还有我的.env文件
DB_HOST="xxxx-shard-00-00-uggj0.mongodb.net"
DB_PORT=27017
DB_DATABASE=xxx
DB_USERNAME=xxx
DB_PASSWORD=xxx
我收到此错误
我与Mongodb Compass进行了冷连接,没有问题.
I cold conect with Mongodb Compass without problem.
我的地图集 Ip白名单已打开(0.0.0.0/0).
My Atlas Ip Whitelist is open (0.0.0.0/0).
我想念什么吗?
推荐答案
在Laravel中,使用config/database.php中的"dsn"键,如下所示,以提及完整的集群URL.
In Laravel, Use 'dsn' key in config/database.php as shown below to mention the complete cluster url.
'mongodb_conn' => [
'driver' => 'mongodb',
'dsn'=>'mongodb://username:password@host1,host2/database?ssl=true&replicaSet=replicaSet&authSource=admin',
'database' => 'my_data',
]
这篇关于将Laravel Jenssegers连接到MongoDB Atlas集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!