Docs Menu
Docs Home
/
Monitor Clusters
/

Use MongoDB Search Instead of Regex Queries

If your queries rely on regex matching, you can improve the performance and efficiency of your query by creating a MongoDB Search index and running a $search aggregation pipeline stage. $regex is inefficient because it cannot always make use of indexes whereas MongoDB Search indexes significantly improve the performance of your queries and offer more options for customizing query parameters.

This page describes some common MongoDB Search index and query configurations for $regex use cases.

The examples use an sample_mflix.movies namespace. To run the sample queries, add this collection to your cluster or use the pre-configured snapshots in the MongoDB Search Playground. The sample queries demonstrate how to use $search instead of $regex for the following use cases:

On this page