Skip to content

Instantly share code, notes, and snippets.

@munro
Created November 16, 2012 17:20
Show Gist options
  • Save munro/4089156 to your computer and use it in GitHub Desktop.
Save munro/4089156 to your computer and use it in GitHub Desktop.
MongoDB Match Regexp
db.eval(function (str) {
return db.foo.find({$where: function () {
return str.match(this.regexp);
});
}, "match this");
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