Text Search with regex
It would be great if Text Search allows us to query with regular expressions. E.g.
mycoll.find({ $text: { $search: "super%"} })
Thank you for considering my request.
1
vote
Hugo
shared this idea
-
Hugo commented
I am not sure if in this way text index is used. Is it?
-
AdminMarcus Eagan (Admin, MongoDB) commented
You can do text search with regex but it won't use the syntax you included above. You can read about the syntax here:
https://docs.atlas.mongodb.com/atlas-search/regex/
Here is an example from the docs:
db.movies.aggregate([
{
"$search": {
"regex": {
"path": "title",
"query": "(.*) Seattle"
}
}
},
{
$project: {
"_id": 0,
"title": 1
}
}
])