Commit 7f05cca1 authored by Jens Segers's avatar Jens Segers

Adding regex operation

parent 288c3d70
...@@ -256,6 +256,12 @@ Selects documents if the array field is a specified size. ...@@ -256,6 +256,12 @@ Selects documents if the array field is a specified size.
User::where('tags', 'size', 3)->get(); 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** **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 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
......
...@@ -26,7 +26,7 @@ class Builder extends \Illuminate\Database\Query\Builder { ...@@ -26,7 +26,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
'=', '<', '>', '<=', '>=', '<>', '!=', '=', '<', '>', '<=', '>=', '<>', '!=',
'like', 'not like', 'between', 'ilike', 'like', 'not like', 'between', 'ilike',
'&', '|', '^', '<<', '>>', '&', '|', '^', '<<', '>>',
'exists', 'type', 'mod', 'where', 'all', 'size', 'exists', 'type', 'mod', 'where', 'all', 'size', 'regex',
); );
/** /**
......
...@@ -496,6 +496,10 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase { ...@@ -496,6 +496,10 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
$results = DB::collection('items')->where('tags', 'size', 4)->get(); $results = DB::collection('items')->where('tags', 'size', 4)->get();
$this->assertEquals(1, count($results)); $this->assertEquals(1, count($results));
$regex = new MongoRegex("/.*doe/i");
$results = DB::collection('users')->where('name', 'regex', $regex)->get();
$this->assertEquals(2, count($results));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment