Skip to content

Instantly share code, notes, and snippets.

@DenisGorbachev
Last active August 22, 2019 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DenisGorbachev/4a97368af572b2a94db6d5dbf0dcee99 to your computer and use it in GitHub Desktop.
Save DenisGorbachev/4a97368af572b2a94db6d5dbf0dcee99 to your computer and use it in GitHub Desktop.
~/.mongorc.js
RegExp.escape = function(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
};
DBCollection.prototype.findOld = DBCollection.prototype.find;
DBCollection.prototype.find = function(query, fields) {
if (typeof query === 'string') {
var re = new RegExp(RegExp.escape(query), "i");
query = {$or: [{_id: re}, {name: re}, {title: re}, {text: re}, {"emails.address": re}]};
}
return this.findOld(query, fields);
}
DBQuery.prototype._prettyShell = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment