Skip to content

Instantly share code, notes, and snippets.

@matthewbordas
Created March 13, 2019 22:04
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 matthewbordas/2248c86ed382b0a03ea82d9d85abb612 to your computer and use it in GitHub Desktop.
Save matthewbordas/2248c86ed382b0a03ea82d9d85abb612 to your computer and use it in GitHub Desktop.
Find object in MongoDB via Regex
/* This will perform a case insensitive search in the
* collection specified by 'CollectionName', against the field
* specified by 'targetField', for all strings in the field that contain
* the substring specified by 'substring'.
* This was tested primarily in the Mongo Shell.
*
* Source: https://stackoverflow.com/a/10610461/3559330
*/
db.getCollection('CollectionName').find({targetField: /substring/i})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment