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