Example:
> db.stuff.save({"foo":"bar"});
> db.stuff.find({"foo":"bar"}).count();
1
> db.stuff.find({"foo":"BAR"}).count();
0
Example:
> db.stuff.save({"foo":"bar"});
> db.stuff.find({"foo":"bar"}).count();
1
> db.stuff.find({"foo":"BAR"}).count();
0
Suppose you want to search "column" in "Table" and you want case insenstive search. The best and efficient way is as below;
Above code just adds your search value as RegEx and searches in with insensitve criteria set with "i" as option.
All the best.
The aggregation framework was introduced in mongodb 2.2 . You can use the string operator "$strcasecmp" to make a case-insensitive comparison between strings. It's more recommended and easier than using regex.
Here's the official document on the aggregation command operator: https://docs.mongodb.com/manual/reference/operator/aggregation/strcasecmp/#exp._S_strcasecmp .
You could use a regex.
In your example that would be:
I must say, though, maybe you could just downcase (or upcase) the value on the way in rather than incurring the extra cost every time you find it. Obviously this wont work for people's names and such, but maybe use-cases like tags.
These have been tested for string searches
Mongo (current version 2.0.0) doesn't allow case-insensitive searches against indexed fields - see their documentation. For non-indexed fields, the regexes listed in the other answers should be fine.
As you can see in mongo docs - since version 3.2
$text
index is case-insensitive by default: https://docs.mongodb.com/manual/core/index-text/#text-index-case-insensitivityCreate a text index and use $text operator in your query.