I'm using laravel 5.2 and MongoDB 3.2.
I want to test if connection with is ok before my app starts (i can't use DB facade), in the monolog configuration. If connection is not ok, i will use logging in file.
By recommendation, i'm testing MongoClient, Mongo and MongoDB\Client, and using whatever is enabled.
I'm trying to test mongo connect as the following:
$mongoClient = new \MongoDB\Client('mongodb://localhost:27017');
$mongoClient->selectCollection('mydb', 'mycollection');
That's the return:
Client {
+manager: Manager {#21}
+uri: "mongodb://localhost:27017"
+typeMap: [
array => "MongoDB\Model\BSONArray",
document => "MongoDB\Model\BSONDocument",
root => "MongoDB\Model\BSONDocument"
]
}
Finnaly, my questions:
- Exists a way to use DB facade before app starts?
- How and what is the right way to test MongoDB connection with PHP?
If you has another suggestion, i will be thankful.