Mongodb check if connection is ok via Laravel/PHP
<p>I'm using laravel 5.2 and MongoDB 3.2.</p>

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

<p>By recommendation, i'm testing MongoClient, Mongo and MongoDB\Client, and using whatever is enabled.</p>

<p>I'm trying to test mongo connect as the following:</p>

<pre><code>$mongoClient = new \MongoDB\Client('mongodb://localhost:27017');
$mongoClient-&gt;selectCollection('mydb', 'mycollection');
</code></pre>

<p>That's the return:</p>

<pre><code>Client {   
    +manager: Manager {#21}
    +uri: "mongodb://localhost:27017"   
    +typeMap: [
        array =&gt; "MongoDB\Model\BSONArray",
        document =&gt; "MongoDB\Model\BSONDocument",
        root =&gt; "MongoDB\Model\BSONDocument"   
    ]
}
</code></pre>

<p>Finnaly, my questions:</p>

<ul>
<li>Exists a way to use DB facade before app starts?</li>
<li>How and what is the right way to test MongoDB connection with PHP?</li>
</ul>

<p>If you has another suggestion, i will be thankful.</p>