Mongodb check if connection is ok via Laravel/PHP -


i'm using laravel 5.2 , mongodb 3.2.

i want test if connection ok before app starts (i can't use db facade), in monolog configuration. if connection not ok, use logging in file.

by recommendation, i'm testing mongoclient, mongo , mongodb\client, , using whatever enabled.

i'm trying test mongo connect following:

$mongoclient = new \mongodb\client('mongodb://localhost:27017'); $mongoclient->selectcollection('mydb', 'mycollection'); 

that's return:

client {        +manager: manager {#21}     +uri: "mongodb://localhost:27017"        +typemap: [         array => "mongodb\model\bsonarray",         document => "mongodb\model\bsondocument",         root => "mongodb\model\bsondocument"        ] } 

finnaly, questions:

  • exists way use db facade before app starts?
  • how , right way test mongodb connection php?

if has suggestion, thankful.

according php document, the driver connects database lazily (http://php.net/manual/en/mongodb-driver-manager.getservers.php), way test connection should execute commands findone() stated in yours comment.

in addition, if name of db or collection uncertain @ point, can use listdatabases() method throws exceptions if connection fails.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -