PHP mongoDB cluster connection string is not workingHow can I prevent SQL injection in PHP?Deleting an element from an array in PHPHow to query MongoDB with “like”?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?mongodb connect using phpReference - What does this error mean in PHP?Why shouldn't I use mysql_* functions in PHP?php failed to connect to mongodb socketUnreachable MongoDB replica set using MAMP
Is "you will become a subject matter expert" code for "you'll be working on your own 100% of the time"?
Output a Super Mario Image
Bit one of the Intel 8080's Flags register
A simple problem about Rule
Make 2019 with single digits
Are space camera sensors usually round, or square?
Write a function that returns an iterable object of all valid points 4-directionally adjacent to (x, y)
How are unbalanced coaxial cables used for broadcasting TV signals without any problems?
How to stabilise the bicycle seatpost and saddle when it is all the way up?
Why is the T-1000 humanoid?
Is there any way to land a rover on the Moon without using any thrusters?
Difference in using Lightning Component <lighting:badge/> and Normal DOM with slds <span class="slds-badge"></span>? Which is Better and Why?
Finding the number of digits of a given integer.
Can I fix my boots by gluing the soles back on?
Can you add polynomial terms to multiple linear regression?
Karazuba Algorithm with arbitrary bases
How does a simple logistic regression model achieve a 92% classification accuracy on MNIST?
Where to disclose a zero day vulnerability
Thematic, genred concepts in Ancient Greek?
In Germany, how can I maximize the impact of my charitable donations?
Why is the Digital 0 not 0V in computer systems?
I was promised a work PC but still awaiting approval 3 months later so using my own laptop - Is it fair to ask employer for laptop insurance?
What's 待ってるから mean?
Can I tap all my opponent's lands while they're casting a spell to negate it?
PHP mongoDB cluster connection string is not working
How can I prevent SQL injection in PHP?Deleting an element from an array in PHPHow to query MongoDB with “like”?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?mongodb connect using phpReference - What does this error mean in PHP?Why shouldn't I use mysql_* functions in PHP?php failed to connect to mongodb socketUnreachable MongoDB replica set using MAMP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to connect to mongoDB cluster from PHP using below code
$client = new MongoClient('mongodb+srv://username:password@urlToCluster');
It gives me error as
Uncaught exception 'MongoConnectionException' with message 'MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known'
Not able to connect using connection string
php mongodb
add a comment
|
I am trying to connect to mongoDB cluster from PHP using below code
$client = new MongoClient('mongodb+srv://username:password@urlToCluster');
It gives me error as
Uncaught exception 'MongoConnectionException' with message 'MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known'
Not able to connect using connection string
php mongodb
The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Alsomongodb+srv
would not be used forlocal
and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be usingmongodb+srv
and just meanmongodb://
or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.
– Neil Lunn
Mar 28 at 10:39
I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB
– hrishi
Mar 28 at 10:44
Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.
– Neil Lunn
Mar 28 at 10:48
but using same credentials I can connect from terminal successfully.
– hrishi
Mar 28 at 11:51
add a comment
|
I am trying to connect to mongoDB cluster from PHP using below code
$client = new MongoClient('mongodb+srv://username:password@urlToCluster');
It gives me error as
Uncaught exception 'MongoConnectionException' with message 'MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known'
Not able to connect using connection string
php mongodb
I am trying to connect to mongoDB cluster from PHP using below code
$client = new MongoClient('mongodb+srv://username:password@urlToCluster');
It gives me error as
Uncaught exception 'MongoConnectionException' with message 'MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known'
Not able to connect using connection string
php mongodb
php mongodb
edited Mar 28 at 10:44
hrishi
asked Mar 28 at 10:26
hrishihrishi
5503 gold badges11 silver badges28 bronze badges
5503 gold badges11 silver badges28 bronze badges
The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Alsomongodb+srv
would not be used forlocal
and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be usingmongodb+srv
and just meanmongodb://
or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.
– Neil Lunn
Mar 28 at 10:39
I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB
– hrishi
Mar 28 at 10:44
Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.
– Neil Lunn
Mar 28 at 10:48
but using same credentials I can connect from terminal successfully.
– hrishi
Mar 28 at 11:51
add a comment
|
The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Alsomongodb+srv
would not be used forlocal
and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be usingmongodb+srv
and just meanmongodb://
or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.
– Neil Lunn
Mar 28 at 10:39
I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB
– hrishi
Mar 28 at 10:44
Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.
– Neil Lunn
Mar 28 at 10:48
but using same credentials I can connect from terminal successfully.
– hrishi
Mar 28 at 11:51
The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Also
mongodb+srv
would not be used for local
and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be using mongodb+srv
and just mean mongodb://
or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.– Neil Lunn
Mar 28 at 10:39
The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Also
mongodb+srv
would not be used for local
and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be using mongodb+srv
and just mean mongodb://
or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.– Neil Lunn
Mar 28 at 10:39
I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB
– hrishi
Mar 28 at 10:44
I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB
– hrishi
Mar 28 at 10:44
Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.
– Neil Lunn
Mar 28 at 10:48
Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.
– Neil Lunn
Mar 28 at 10:48
but using same credentials I can connect from terminal successfully.
– hrishi
Mar 28 at 11:51
but using same credentials I can connect from terminal successfully.
– hrishi
Mar 28 at 11:51
add a comment
|
1 Answer
1
active
oldest
votes
MongoClient is deprecated long time ago and likely doesn't support new replica set syntax.
https://docs.atlas.mongodb.com/driver-connection/ recommends to use up to date Mongodb driver:
$client = new MongoDBClient('mongodb+srv:////username:password@urlToCluster/?ssl=true&authSource=admin');
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395284%2fphp-mongodb-cluster-connection-string-is-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
MongoClient is deprecated long time ago and likely doesn't support new replica set syntax.
https://docs.atlas.mongodb.com/driver-connection/ recommends to use up to date Mongodb driver:
$client = new MongoDBClient('mongodb+srv:////username:password@urlToCluster/?ssl=true&authSource=admin');
add a comment
|
MongoClient is deprecated long time ago and likely doesn't support new replica set syntax.
https://docs.atlas.mongodb.com/driver-connection/ recommends to use up to date Mongodb driver:
$client = new MongoDBClient('mongodb+srv:////username:password@urlToCluster/?ssl=true&authSource=admin');
add a comment
|
MongoClient is deprecated long time ago and likely doesn't support new replica set syntax.
https://docs.atlas.mongodb.com/driver-connection/ recommends to use up to date Mongodb driver:
$client = new MongoDBClient('mongodb+srv:////username:password@urlToCluster/?ssl=true&authSource=admin');
MongoClient is deprecated long time ago and likely doesn't support new replica set syntax.
https://docs.atlas.mongodb.com/driver-connection/ recommends to use up to date Mongodb driver:
$client = new MongoDBClient('mongodb+srv:////username:password@urlToCluster/?ssl=true&authSource=admin');
answered Mar 28 at 12:45
Alex BlexAlex Blex
18.5k2 gold badges24 silver badges52 bronze badges
18.5k2 gold badges24 silver badges52 bronze badges
add a comment
|
add a comment
|
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395284%2fphp-mongodb-cluster-connection-string-is-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Also
mongodb+srv
would not be used forlocal
and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be usingmongodb+srv
and just meanmongodb://
or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.– Neil Lunn
Mar 28 at 10:39
I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB
– hrishi
Mar 28 at 10:44
Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.
– Neil Lunn
Mar 28 at 10:48
but using same credentials I can connect from terminal successfully.
– hrishi
Mar 28 at 11:51