How to find a substring in a field in mongodb?

by muriel.schmidt , in category: MySQL , 2 days ago

How to find a substring in a field in mongodb?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raven_corwin , a day ago

@muriel.schmidt 

You can find a substring in a field in MongoDB using the $regex operator. Here's an example query that finds all documents in a collection where the "field" contains the substring "abc":

1
db.collection.find({ field: { $regex: 'abc' } })


This query will return all documents where the "field" contains the substring "abc". You can also use regular expressions for more complex pattern matching. Just replace 'abc' in the example above with your desired substring.