title: MongoDB & PHP get only product that matches barcode
body: <p>I have this JSON and you can see under products i have barcodes for each product what i want to do is only get the information that matches the product barcode</p>
  
  <pre><code>{
    "company": "village",
    "logo": "http:\/\/www.incard.com.au\/newsite\/template\/images\/movieticket\/4cinemas\/villagetop.png",
    "products": [
      {
        "barcode": "236690091",
        "name": "Weekday",
        "logo-URL": "http: \/\/www.incard.com.au\/newsite\/template\/images\/movieticket\/4cinemas\/ticketpic1.png",
        "price": "12.50",
        "discount": "1.50"
      },
      {
        "barcode": "236690092",
        "name": "Weekend",
        "logo-URL": "http: \/\/www.incard.com.au\/newsite\/template\/images\/movieticket\/4cinemas\/ticketpic1.png",
        "price": "13.50",
        "discount": "1.60"
      },
      {
        "barcode": "236690093",
        "name": "Gold Class",
        "logo-URL": "http: \/\/www.incard.com.au\/newsite\/template\/images\/movieticket\/4cinemas\/ticketpic1.png",
        "price": "13.50",
        "discount": "1.60"
      }
    ],
    "store_name": "movies"
  }
  </code></pre>
  
  <p>for example If i hit 236690091 I only what the database (MongoDB) to return</p>
  
  <pre><code>"barcode": "236690091",
        "name": "Weekday",
        "logo-URL": "http: \/\/www.incard.com.au\/newsite\/template\/images\/movieticket\/4cinemas\/ticketpic1.png",
        "price": "12.50",
        "discount": "1.50"
  </code></pre>
  
  <p>not every product.</p>
  
  <p>This is what I have tried</p>
  
  <pre><code>public function getbarcode($barcode)
      {
          // select a collection (analogous to a relational database's table)
           $collection = $this-&gt;db-&gt;movies-&gt;products;
  
          // find everything in the collection
          $cursor = $collection-&gt;find(array("barcode" =&gt;"{$barcode}"));
  
          $test = array();
              // iterate through the results
              while( $cursor-&gt;hasNext() ) {
                  $test[] = ($cursor-&gt;getNext());
              }
          //Print Results 
          print json_encode($test);
  
      }
  </code></pre>