MongoCollection::distinct PHP Method

distinct() public method

Retrieve a list of distinct values for the given key across a collection
public distinct ( string $key, array $query = [] ) : array | boolean
$key string The key to use.
$query array An optional query parameters
return array | boolean Returns an array of distinct values, or FALSE on failure
    public function distinct($key, array $query = [])
    {
        try {
            return array_map([TypeConverter::class, 'toLegacy'], $this->collection->distinct($key, TypeConverter::fromLegacy($query)));
        } catch (\MongoDB\Driver\Exception\Exception $e) {
            return false;
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Retrieve a list of distinct values for the given key across a collection.
  *
  * @param string $selector field selector
  * @param array|callable|\Sokil\Mongo\Expression $expression expression to search documents
  * @return array distinct values
  */
 public function getDistinct($selector, $expression = null)
 {
     if ($expression) {
         return $this->_mongoCollection->distinct($selector, Expression::convertToArray($expression));
     }
     return $this->_mongoCollection->distinct($selector);
 }
All Usage Examples Of MongoCollection::distinct