0

Ok, so I have a collection in my MongoDB

here is a sample my key here is

company

{
   "_id": ObjectId("4fdfe7b536314b4147000000"),
   "company": "hoyts",
   "barcode": "236602253",
   "name": "Gold Class",
   "logoURL": "http: \/\/www.incard.com.au\/newsite\/template\/images\/movieticket\/4cinemas\/ticketpic1.png",
   "store_name": "movies" 
}

Now the issue here is I have 4 rows/collects with hoyts, I need away to group them.

my current code

public function getstore($storename)
    {
        // select a collection (analogous to a relational database's table)
         $collection = $this->db->products;

        // find everything in the collection
        $cursor = $collection->find(array("store_name"=>$storename));

        $test = array();
            // iterate through the results
            while( $cursor->hasNext() ) {
                $test[] = ($cursor->getNext());
            }
        //Print Results 
        print json_encode($test);

    }

I tried using

group($key)->find

however that did not work.

Could someone give me a hand thanks

4

1 回答 1

1

看这个例子: http: //php.net/manual/en/mongocollection.group.php

于 2012-06-19T03:40:08.130 回答