【发布时间】:2016-05-25 15:24:34
【问题描述】:
在 mongo shell 中查询:
db.collections.distinct('user_id');
简单地给出不同的文件。 我正在研究 phalcon,没有像
这样的选项 Collections::distinct()
那么我如何在 phalcon 中查询 distinct。请帮帮我
【问题讨论】:
在 mongo shell 中查询:
db.collections.distinct('user_id');
简单地给出不同的文件。 我正在研究 phalcon,没有像
这样的选项 Collections::distinct()
那么我如何在 phalcon 中查询 distinct。请帮帮我
【问题讨论】:
也许 Phalcon 在论坛中的回答会有所帮助:https://forum.phalconphp.com/discussion/6832/option-for-function-distinct-phalconmvccollection
他们建议使用聚合:
$data = Article::aggregate(
array(
array(
'$project' => array('category' => 1)
),
array(
'$group' => array(
'_id' => array('category' => '$category'),
'id' => array('$max' => '$_id')
)
)
)
);
【讨论】: