title: How join two table in mongodb and select all the details from both table?
body: <p>I have two collections one is order_master and the other one is product_master.
  I need to fetch only those order which have the particular product name say 'tops'</p>
  
  <p>Here is my my collection
  Order Master</p>
  
  <pre><code>_id
  o_type
  product_data
    -&gt;0
      -&gt;product_id
      -&gt;shipping_details
  </code></pre>
  
  <p>Product_master</p>
  
  <pre><code>_id
  product_name
  product_type
  </code></pre>
  
  <p>based on product name I have to select the order details</p>
  
  <p>for Eg:</p>
  
  <p>Select * from order_master om inner join product_master pm on pm._id = om.product_data.product_id where pm.product_name = 'top'</p>
  
  <p>similar like this</p>
  
  <p>How to write in mongo db</p>
  
  <p>I have tried like this</p>
  
  <pre><code>$collection = $this-&gt;mongo_db-&gt;db-&gt;selectCollection('product_master');   
  $request = $collection-&gt;aggregate(
                      array(
                          '$match' =&gt; array(
                              '$and' =&gt; array(
                                  array('product_name' =&gt; 'top')        
                              )
                          )
                      ),
                      array(
                          '$lookup' =&gt; array(
                              'from' =&gt; "order_master",
                              'localField' =&gt; "product_data.p_id",
                              'foreignField' =&gt; "_id",
                              'as' =&gt; "product_data"
                          )
                      )
                  );
  </code></pre>