Created
November 16, 2012 17:20
-
-
Save munro/4089156 to your computer and use it in GitHub Desktop.
MongoDB Match Regexp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| db.eval(function (str) { | |
| return db.foo.find({$where: function () { | |
| return str.match(this.regexp); | |
| }); | |
| }, "match this"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| db.foo.find({$where: '(' + function (scope) { | |
| return function () { | |
| return scope.str.match(this.regexp); | |
| }; | |
| }.toString() + '(' + JSON.stringify({ | |
| str: 'hello' | |
| }) + '))'}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment