Voting

: zero minus zero?
(Example: nine)

The Note You're Voting On

maha88a
9 years ago
Here is an example of Query to retrieve the records from MangoDB collection using a filter. It will return in this case just one record that satisfy the filter id = 2.

Considering the following MangoDB collection:

<?php
/* my_collection */

/* 1 */
{
"_id" : ObjectId("5707f007639a94cbc600f282"),
"id" : 1,
"name" : "Name 1"
}

/* 2 */
{
"_id" : ObjectId("5707f0a8639a94f4cd2c84b1"),
"id" : 2,
"name" : "Name 2"
}
?>

I'm using the following code:
<?php
$filter
= ['id' => 2];
$options = [
'projection' => ['_id' => 0],
];
$query = new MongoDB\Driver\Query($filter, $options);
$rows = $mongo->executeQuery('db_name.my_collection', $query); // $mongo contains the connection object to MongoDB
foreach($rows as $r){
print_($r);
}
?>

<< Back to user notes page

To Top