I'm trying to connect to a mongodb using this configuration in web.php:
'mongodb' => [
'class' => '\yii\mongodb\Connection',
'dsn' => 'mongodb://user:password@10.16.22.72:27017/mobiledata_db',
'options' => [
"username" => "********",
"password" => "*******"
]
],
and it's throwing the following error
MongoDB Exception – yii\\mongodb\\Exception No suitable servers found (
serverSelectionTryOnce
set): [socket timeout calling ismaster on '10.16.22.72:27017'] ↵ Caused by: MongoDB\\Driver\\Exception\\ConnectionTimeoutException No suitable servers found (serverSelectionTryOnce
set): [socket timeout calling ismaster on '10.16.22.72:27017']
To mention that i'm able to connect to mongo using compass and ssh.
Do i have to use ssh in connection string? If so how do i do it?
To do that i ha to set up a tunneled ssh:
ssh -fNg -L 27017:127.0.0.1:27017 user@host
And that fixed my problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.