Sokil\Mongo\Pipeline::match PHP Method

match() public method

Filter documents by expression
public match ( array | Expression $expression ) : Pipeline
$expression array | Expression
return Pipeline
    public function match($expression)
    {
        if (is_callable($expression)) {
            $expressionConfigurator = $expression;
            $expression = new Expression();
            call_user_func($expressionConfigurator, $expression);
        }
        if ($expression instanceof Expression) {
            $expression = $expression->toArray();
        } elseif (!is_array($expression)) {
            throw new Exception('Must be array, callable or instance of \\Sokil\\Mongo\\Expression');
        }
        $this->addStage('$match', $expression);
        return $this;
    }

Usage Example

示例#1
0
 public function testPipeline_MatchArray()
 {
     $pipeline = new Pipeline($this->collection);
     $pipeline->match(array('a' => 1, 'b' => array('$lt' => 12)));
     $this->assertEquals('[{"$match":{"a":1,"b":{"$lt":12}}}]', (string) $pipeline);
 }