Quantcast
Channel: How to query MongoDB with "like" - Stack Overflow
Viewing all articles
Browse latest Browse all 48

Answer by Rust for How to query MongoDB with "like"?

$
0
0

Regex are expensive are process.

Another way is to create an index of text and then search it using $search.

Create a text Index of fields you want to make searchable:

db.collection.createIndex({name: 'text', otherField: 'text'});

Search for a string in text index:

db.collection.find({
  '$text'=>{'$search': "The string"}
})

Viewing all articles
Browse latest Browse all 48


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>