public function evaluate($code, $cb)
    {
        $p = [];

        if (!isset($p['offset'])) {
            $p['offset'] = 0;
        }

        if (!isset($p['limit'])) {
            $p['limit'] = -1;
        }

        if (!isset($p['opts'])) {
            $p['opts'] = 0;
        }

        if (!isset($p['db'])) {
            $p['db'] = $this->dbname;
        }

        $cb = CallbackWrapper::wrap($cb);
        try {
            $this->request(
                self::OP_QUERY,
                pack('V', $p['opts']) . $p['db'] . '.$cmd' . "\x00"
                . pack('VV', $p['offset'], $p['limit']) . bson_encode(['$eval' => new \MongoCode($code)])
                . (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['db'], $cb, true];
                }
            );
        } catch (\MongoException $e) {
            Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString());
            if ($cb !== null) {
                $cb([
                    '$err' => $e->getMessage(),
                    '$query' => $query,
                    '$fields' => isset($p['fields']) ? $p['fields'] : null
                ]);
            }
        }
    }
public function evaluate($code, $cb)
    {
        $p = [];

        if (!isset($p['offset'])) {
            $p['offset'] = 0;
        }

        if (!isset($p['limit'])) {
            $p['limit'] = -1;
        }

        if (!isset($p['opts'])) {
            $p['opts'] = 0;
        }

        if (!isset($p['db'])) {
            $p['db'] = $this->dbname;
        }

        $cb = CallbackWrapper::wrap($cb);
        try {
            $this->request(
                self::OP_QUERY,
                pack('V', $p['opts']) . $p['db'] . '.$cmd' . "\x00"
                . pack('VV', $p['offset'], $p['limit']) . bson_encode(['$eval' => new \MongoCode($code)])
                . (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['db'], $cb, true];
                }
            );
        } catch (\MongoException $e) {
            Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString());
            if ($cb !== null) {
                $cb([
                    '$err' => $e->getMessage(),
                    '$query' => $query,
                    '$fields' => isset($p['fields']) ? $p['fields'] : null
                ]);
            }
        }
    }
public function evaluate ( $ code , $ cb ) { $ p = [ ] ; if ( ! isset ( $ p [ 'offset' ] ) ) { $ p [ 'offset' ] = 0 ; } if ( ! isset ( $ p [ 'limit' ] ) ) { $ p [ 'limit' ] = - 1 ; } if ( ! isset ( $ p [ 'opts' ] ) ) { $ p [ 'opts' ] = 0 ; } if ( ! isset ( $ p [ 'db' ] ) ) { $ p [ 'db' ] = $ this -> dbname ; } $ cb = CallbackWrapper :: wrap ( $ cb ) ; try { $ this -> request ( self :: OP_QUERY , pack ( 'V' , $ p [ 'opts' ] ) . $ p [ 'db' ] . '.$cmd' . "\x00" . pack ( 'VV' , $ p [ 'offset' ] , $ p [ 'limit' ] ) . bson_encode ( [ '$eval' => new \ MongoCode ( $ code ) ] ) . ( 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 [ 'db' ] , $ cb , true ] ; } ) ; } catch ( \ MongoException $ e ) { Daemon :: log ( 'MongoClient exception: ' . $ e -> getMessage ( ) . ': ' . $ e -> getTraceAsString ( ) ) ; if ( $ cb !== null ) { $ cb ( [ '$err' => $ e -> getMessage ( ) , '$query' => $ query , '$fields' => isset ( $ p [ 'fields' ] ) ? $ p [ 'fields' ] : null ] ) ; } } }
Evaluates a code on the server side
@param  string $code Code
@param  callable $cb Callback called when response received
@callback $cb ( )
@return void
Evaluates a code on the server side