How to get count distinct values from the collection using query? Now I am using this solution:
$collection = Yii::$app->mongodb->getCollection('collection_name');
$result = $collection->distinct('field_id');
return count($result);
Collection example:
{
{a: 2},
{a: 2},
{b: 3},
{c: 4}
}
Result must be:
3