如何通过 mongodb phalcon 中的某些字段获取不同的文档?

How to get distinct documents by some field in mongodb phalcon?

在mongoshell查询中:

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