MongoDB Group by Key PHP

时间:2012-06-19 02:58:33

标签: php mongodb mongodb-php

好的,我的MongoDB中有一个集合

这里有一个示例,我的密钥是

  

公司

{
   "_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" 
}

现在问题是我有4行/收集hoyts,我需要将它们分组。

我当前的代码

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);

    }

我尝试使用

  

组($键) - >找到

然而,这不起作用。

有人可以帮我一臂谢谢

1 个答案:

答案 0 :(得分:1)