Skip to content

Commit 7f05cca

Browse files
committed
Adding regex operation
1 parent 288c3d7 commit 7f05cca

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ Selects documents if the array field is a specified size.
256256

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

259+
**Regex**
260+
261+
Selects documents where values match a specified regular expression.
262+
263+
User::where('name', 'regex', new MongoRegex("/.*doe/i"))->get();
264+
259265
**Type**
260266

261267
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

src/Jenssegers/Mongodb/Query/Builder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
2626
'=', '<', '>', '<=', '>=', '<>', '!=',
2727
'like', 'not like', 'between', 'ilike',
2828
'&', '|', '^', '<<', '>>',
29-
'exists', 'type', 'mod', 'where', 'all', 'size',
29+
'exists', 'type', 'mod', 'where', 'all', 'size', 'regex',
3030
);
3131

3232
/**

tests/QueryBuilderTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ public function testOperators()
496496

497497
$results = DB::collection('items')->where('tags', 'size', 4)->get();
498498
$this->assertEquals(1, count($results));
499+
500+
$regex = new MongoRegex("/.*doe/i");
501+
$results = DB::collection('users')->where('name', 'regex', $regex)->get();
502+
$this->assertEquals(2, count($results));
499503
}
500504

501505
}

0 commit comments

Comments
 (0)