Last active
August 29, 2015 14:13
-
-
Save tvdsluijs/4dfb175a33b7913a750c to your computer and use it in GitHub Desktop.
Mongodb php aggregation $match 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 | |
$ops = array( | |
array( | |
'$match' => array("category" => 'socks') | |
) | |
); | |
$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