Created
July 27, 2020 13:32
-
-
Save hrishi7/517bd1596f2bb5a880cae8b54bbadb30 to your computer and use it in GitHub Desktop.
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
21 | |
I was having same problem with my title and after lots of searching, i found this answer Here, | |
var search = 'Joe'; | |
db.users.find(name: /^search/) | |
db.users.find(name: {$regex: /^search/}); | |
db.users.find(name: {$regex: "/^" + search + "/"}); | |
The queries above won’t return anything. The solution to this little problem is quite simple: | |
db.users.find(name: new RegExp(search)) //For substring search, case sensitive. | |
db.users.find(name: new RegExp('^' + search + '$')) //For exact search, case sensitive | |
db.users.find(name: new RegExp(search, ‘i')) //For substring search, case insensitive | |
db.users.find(name: new RegExp('^' +search + '$', 'i')); //For exact search, case insensitiv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment