using $regex in mongodb, I want to find the name B&B Hôtel which contain some special characters like & and ô by typing BB Hotel.
I tried this code:
db.txt.find({ "name": {'$regex': query, $options:'i'}})
where query can be BB Hotel.
using $regex in mongodb, I want to find the name B&B Hôtel which contain some special characters like & and ô by typing BB Hotel.
I tried this code:
db.txt.find({ "name": {'$regex': query, $options:'i'}})
where query can be BB Hotel.
You don't want regex search, you want diacritic insensitive text search
"name":{
$text:
{
$search: "\"B&B Hotel\""
$caseSensitive: false,
$diacriticSensitive: false
}
}
Note that $diacriticSensitive defaults to false, but I never trust the defaults. If you are running with older indexes (version 2 or less text index), you may not be able to use the indexes. The escaped " in the search part is to search for this phrase.