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;








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










share|improve this question


























  • 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











  • 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

















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










share|improve this question


























  • 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











  • 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













0












0








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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. 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











  • 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











  • 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












1 Answer
1






active

oldest

votes


















1
















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');





share|improve this answer
























    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
    );



    );














    draft saved

    draft discarded
















    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









    1
















    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');





    share|improve this answer





























      1
















      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');





      share|improve this answer



























        1














        1










        1









        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');





        share|improve this answer













        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');






        share|improve this answer












        share|improve this answer



        share|improve this answer










        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





















            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.




















            draft saved

            draft discarded















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

            Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?