Created
March 13, 2019 22:04
-
-
Save matthewbordas/2248c86ed382b0a03ea82d9d85abb612 to your computer and use it in GitHub Desktop.
Find object in MongoDB via Regex
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
/* 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