Hi,
I’m using the PHP driver for the first time and get this error message. I try to get a connection from a php based host to a mongoDB container.
I’ve installed MongoDB extension version > 1.8. The connection to MongoDB through the MongoDB Client seems to be ok (maybe it’s not), but the insertOne function doesn’t work.
Don’t know if something is missing. There are some infos here according this error message, but none of them worked in my case. Would be very grateful for help.
Here’s the code snippet, I use for testing the connection:
try {
$DB_CONNECTION_STRING="mongodb://localhost:27017";
$con = new Client($DB_CONNECTION_STRING);
$db = $con->test;
$collection = $db->tester;
$collection->insertOne(['name'=>'Tom', 'email'=>'tom@tester.com']);
}
catch (\Exception $e) {
print_r($e->getMessage());
}
The output is here:
No suitable servers found (
serverSelectionTryOnce
set): [connection refused calling ismaster on ‘localhost:27017’]
And here is some information from the phpinfo:
MongoDB extension version | 1.9.1 |
---|---|
MongoDB extension stability | stable |
libbson bundled version | 1.17.4 |
libmongoc bundled version | 1.17.4 |
libmongoc SSL | enabled |
libmongoc SSL library | OpenSSL |
libmongoc crypto | enabled |
libmongoc crypto library | libcrypto |
libmongoc crypto system profile | disabled |
libmongoc SASL | disabled |
libmongoc ICU | enabled |
libmongoc compression | enabled |
libmongoc compression snappy | disabled |
libmongoc compression zlib | enabled |
libmongoc compression zstd | disabled |
libmongocrypt bundled version | 1.0.4 |
libmongocrypt crypto | enabled |
libmongocrypt crypto library | libcrypto |