Created
October 11, 2017 08:02
-
-
Save isabellachen/0590976c22ed0f6037b54b146d18e6af to your computer and use it in GitHub Desktop.
Querying MongoDB with Mongoose for RegExp string matching names
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
//if query is 'stephen' it will match 'stephen' and 'stephen hawking' but not 'stephen foobar' | |
//cases ignored | |
Editor.searchEditors = async (query) => { | |
const editors = await Editor.find({'name' : new RegExp(query, "gi")}); | |
if (editors) { | |
return editors; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment