PHPDaemon\Clients\Mongo\Pool::distinct PHP Method

distinct() public method

Returns distinct values of the property
public distinct ( array $p, callable $cb ) : void
$p array Hash of properties (offset, limit, opts, key, col, where)
$cb callable Callback called when response received
return void
    public function distinct($p, $cb)
    {
        $this->_params($p);
        $e = explode('.', $p['col'], 2);
        $query = ['distinct' => $e[1], 'key' => $p['key']];
        if (isset($p[$k = 'rp'])) {
            $v = $p[$k];
            if (is_string($v)) {
                $v = ['mode' => $v];
            }
            $query['$readPreference'] = $v;
        }
        if (isset($p['where'])) {
            $query['query'] = $p['where'];
        }
        $cb = CallbackWrapper::wrap($cb);
        $this->request(self::OP_QUERY, pack('V', $p['opts']) . $e[0] . '.$cmd' . "" . pack('VV', $p['offset'], $p['limit']) . bson_encode($query) . (isset($p['fields']) ? bson_encode($p['fields']) : ''), true, null, function ($conn, $reqId = null) use($p, $cb) {
            if (!$conn) {
                !$cb || $cb(['$err' => 'Connection error.']);
                return;
            }
            $conn->requests[$reqId] = [$p['col'], $cb, true];
        });
    }