Created
January 9, 2015 19:01
-
-
Save tvdsluijs/fc0bb40ee0fe0805df8d to your computer and use it in GitHub Desktop.
Mongodb php aggregation $match $or usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$m = new MongoClient(); // connect to local mongodb | |
$db = $m->products; //select 'mongo database' named products | |
$clothing_col = $db->clothing; //create a collection from the 'table' clothing | |
//create the aggregation | |
//create the Match on clothing-category = shoes or brand = nike | |
$ops = array( | |
array( | |
'$match' => | |
array('$or' => | |
array(array("category" => 'shoes'), | |
array("brand" => 'nike'))) | |
) | |
); | |
$g = $clothing_col->aggregate($ops); //put the aggregation in the function | |
$products = $g['result']; //put results in your own var | |
foreach($products as $product){ | |
echo $product['product_name']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment