Created
March 25, 2015 17:14
-
-
Save javierfdezg/7cac0360ade0982c7ccf to your computer and use it in GitHub Desktop.
Build Mongodb regexp query dynamically
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
var query = {}; | |
var search = { | |
field: 'name', | |
value: 'Your value' | |
}; | |
query[search.field] = { | |
$regex: new Regexp(search.value), | |
$options: "i" | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment