Tuesday, April 11, 2017

PHP MongoDB - eval

I'm struggling to use MongoDB 3.0 eval function in Laravel. All I want is to get to the current operations. Using JS it's super easy, just db.currentOp(). But I need to use a command.

And unfortunately listCommands doesn't return currentOp as possible command. I'm able to run any other command by using this code:

public static function executeCommand($command, $options = [])
    {
        $db = DB::connection('my-connection')->getMongoDB();
        $result = json_decode(json_encode($db->command([$command => 1], $options)->toArray()), TRUE);
        return $result[0];
    }

How the hell could I get current operations list? Walked over all functions and metrics I've found, but neither helped me.



via Rav

Advertisement