Hello
Im just writing this note to help people out who want to write $filter arrays with query operators in them.
I have copied this code off maha88a's note but I changed the $filter to give you an idea of how it would work with the query operators
Considering the following MangoDB collection:
<?php
{
"_id" : ObjectId("5707f007639a94cbc600f282"),
"id" : 1,
"name" : "Name 1"
}
{
"_id" : ObjectId("5707f0a8639a94f4cd2c84b1"),
"id" : 2,
"name" : "Name 2"
}
?>
I'm using the following code:
<?php
$filter = ['id' => ['$gt' => 0]]
$options = [
'projection' => ['_id' => 0],
];
$query = new MongoDB\Driver\Query($filter, $options);
$rows = $mongo->executeQuery('db_name.my_collection', $query); foreach($rows as $r){
print_($r);
}
?>