diff --git a/README.md b/README.md index 2d3990804..84063bceb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Jenssegers/Mongodb/Query/Builder.php b/src/Jenssegers/Mongodb/Query/Builder.php index 688d4e22c..97779d47c 100644 --- a/src/Jenssegers/Mongodb/Query/Builder.php +++ b/src/Jenssegers/Mongodb/Query/Builder.php @@ -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', ); /** diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 619985ebc..67168827c 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -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)); } }