Docker Community Forums

Share and learn in the Docker community.

MongodDb and Php selectCollection method issue?

Am trying to insert data into MongoDB, by using following line code

try{
    $mongo = new Mongo(); //create a connection to MongoDB
    $databases = $mongo->selectDB("test"); //List all databases
    $collection = $database->selectCollection("articles");

    print_r($databases);
    $mongo->close();
} catch(MongoConnectionException $e) {        
    //display connection error and exit
    die($e->getMessage());
}

root cause:

However $collection = $database->selectCollection("articles"); this line of code is not working. If I remove selectCollection() method, it works i.e I am able to connect to mongodb.

Please guide me