Skip to content

Commit

Permalink
Adding regex operation
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Dec 9, 2013
1 parent 288c3d7 commit 7f05cca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ Selects documents if the array field is a specified size.

User::where('tags', 'size', 3)->get();

**Regex**

Selects documents where values match a specified regular expression.

User::where('name', 'regex', new MongoRegex("/.*doe/i"))->get();

**Type**

Selects documents if a field is of the specified type. For more information check: http://docs.mongodb.org/manual/reference/operator/query/type/#op._S_type
Expand Down
2 changes: 1 addition & 1 deletion src/Jenssegers/Mongodb/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
'=', '<', '>', '<=', '>=', '<>', '!=',
'like', 'not like', 'between', 'ilike',
'&', '|', '^', '<<', '>>',
'exists', 'type', 'mod', 'where', 'all', 'size',
'exists', 'type', 'mod', 'where', 'all', 'size', 'regex',
);

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ public function testOperators()

$results = DB::collection('items')->where('tags', 'size', 4)->get();
$this->assertEquals(1, count($results));

$regex = new MongoRegex("/.*doe/i");
$results = DB::collection('users')->where('name', 'regex', $regex)->get();
$this->assertEquals(2, count($results));
}

}

0 comments on commit 7f05cca

Please sign in to comment.