Skip to content

Instantly share code, notes, and snippets.

@isabellachen
Created October 11, 2017 08:02
Show Gist options
  • Save isabellachen/0590976c22ed0f6037b54b146d18e6af to your computer and use it in GitHub Desktop.
Save isabellachen/0590976c22ed0f6037b54b146d18e6af to your computer and use it in GitHub Desktop.
Querying MongoDB with Mongoose for RegExp string matching names
//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