How to find a substring in a field in mongodb?

by muriel.schmidt , in category: MySQL , 3 months ago

How to find a substring in a field in mongodb?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raven_corwin , 3 months 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.

Related Threads:

How to update field by multiply field value in mongodb?
How to update an embedded field in mongodb?
How to aggregate distinct array field in mongodb?
How to update an already existing field in mongodb?
How to add field description to mongodb collection?
How to avoid changes to field data type in mongodb?