mongoclient() to MongoDB\Driver\Manager()

hello, i have an application that i would like to upgrade to php 7.0. this application has mongodb as database connection but the connection i had was with mongoclient.

   $di->set("mongo",function () {
           $mongo = new MongoClient( "mongodb://localhost" );
           return $mongo->selectDB("invoicing");
      }, true );

now i would like to use the new mongo driver:

$di->set("mongo",function () {
       $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); 
       //somehow selectDB('invoicing') ?
       //to be compatible with the rest of the framework
 }, true );

ps: this works, tested with simple script

$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); 
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['x' => 1]);
$bulk->insert(['x' => 2]);
$bulk->insert(['x' => 3]);
$manager->executeBulkWrite('db.invoicing', $bulk);

$filter = ['x' => ['$gt' => 1]];
$options = [
    'projection' => ['_id' => 0],
    'sort' => ['x' => -1],
];

$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $manager->executeQuery('db.invoicing', $query);

foreach ($cursor as $document) {
    var_dump($document);
}

mongodb version 1.1.8

PHP 7.0.11 (cli)

MongoDB shell version: 2.6.10

Tank you, David Correia

Still phalcon just needs to add new MongoDb\Driver support in phalcon 3. But it's a hard job because we are still supporting php 5.x and it's hard to support both versions in one class. We need to seperate codes for each class to other classes to some final class.

hmm, ok i will be waiting then

tank you

>Still phalcon just needs to add new MongoDb\Driver support in phalcon 3. But it's a hard job because we are still supporting php 5.x and it's hard to support both versions in one class. We need to seperate codes for each class to other classes to some final class.

Hi David,

I am also very interestd in this new support for MongoDb\Manager;

Thanks for your work.

Good luck !

Mongo is supported in incubator.