Created
January 9, 2015 18:59
-
-
Save tvdsluijs/757c55049bfecfec9971 to your computer and use it in GitHub Desktop.
Mongodb php aggregation $match $and 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 and brand | |
$ops = array( | |
array( | |
'$match' => | |
array('$and' => | |
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