Last active
August 22, 2019 12:55
-
-
Save DenisGorbachev/4a97368af572b2a94db6d5dbf0dcee99 to your computer and use it in GitHub Desktop.
~/.mongorc.js
This file contains 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
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