This will work with versions >=1.5.3, please note that this is just a example of the way to use the or statement.
<?php
$connection = new Mongo();
$db = $connection->test;
$collection = $db->test;
$collection->drop();
$collection = $db->test;
$apple = array(
'fruit' => 'Apple',
'type' => 'Juice',
);
$orange = array(
'fruit' => 'Orange',
'type' => 'Marmalade',
);
$collection->insert($apple);
$collection->insert($orange);
$results = $collection->find(array('fruit' => 'Apple'));
foreach($results as $result)
{
echo sprintf("Fruit: %s, Type: %s%s", $result['fruit'], $result['type'], PHP_EOL);
}
?>
Output:
Fruit: Apple, Type: Juice
Now an advanced search with "or" statement.
<?php
$results = $collection->find( array( '$or' => array( array('fruit' => 'Apple'), array('fruit' => 'Orange') ) ) );
foreach($results as $result)
{
echo sprintf("Fruit: %s, Type: %s%s", $result['fruit'], $result['type'], PHP_EOL);
}
?>
Output:
Fruit: Apple, Type: Juice
Fruit: Orange, Type: Marmalade