June 2017
Intermediate to advanced
536 pages
9h 49m
English
Fetching data with MongoDB comes down to working with three different classes, MongoDBDriverManager, MongoDBDriverQuery, and MongoDBDriverReadPreference:
<?phprequire_once __DIR__ . '/vendor/autoload.php';try { $manager = new MongoDBDriverManager('mongodb://localhost:27017'); /* Select only the matching documents */ $filter = [ 'price' => [ '$gte' => 619.99, ], ]; $queryOptions = [ /* Return only the following fields in the matching documents */ 'projection' => [ 'name' => 1, 'price' => 1, ], /* Return the documents in descending order of price */ 'sort' => [ 'price' => -1 ] ]; $query = new MongoDBDriverQuery($filter, $queryOptions); $readPreference = new MongoDBDriverReadPreference(MongoDBDriverReadPreference::RP_PRIMARY);
Read now
Unlock full access