HuyPV
Saturday, December 15, 2018
<?php
$connection = new \MongoDB\Driver\Manager("mongodb://192.168.1.69:27017");
#$filter = ['message' => 'XXYYZZYY'];
#$filter = array();
$projection['projection'] = ["_id" => 1,"message" => 1, 'extra.url' => 1];
$projection['limit'] = 10;
$regex1 = new MongoDB\BSON\Regex("^I","i");
$filter = ['level_name' => $regex1];
$query = new \MongoDB\Driver\Query($filter,$projection);
$cursor = $connection->executeQuery('wepay.api_log_local', $query);
foreach($cursor as $key => $row) {
echo($row->message . ': ' . $row->extra->url) . PHP_EOL; //your expected output
}
Title:
PHP sample code query data from MongoDB
Description:
Use PHP to connect to MongoDB and query to get limtied data from collection. It is easy!
...
Rating:
4