Articles → MONGODB → $Regex Operator In Mongodb$Regex Operator In MongodbIn this article, we will discuss the $regex operator in MongoDB.Purpose The $regex operator is used to search the document using the regular expression.Syntax db.collection.find({ "field": { $regex: /pattern/ } })Example In this example, we will use a collection of Articles. We require to get all the documents that contain the word Mongo. So, the query would be: -db.Articles.find({subject:{$regex:/Mongo/}})Similarly, we can query the document to return all documents that start with the word Mongo. For that, we will use ^. The query will be: - db.Articles.find({subject:{$regex:/^Mongo/}})Posted By - Karan Gupta Posted On - Tuesday, March 5, 2024 Query/Feedback Your Email Id** Subject* Query/Feedback Characters remaining 250**
db.collection.find({ "field": { $regex: /pattern/ } })
db.Articles.find({subject:{$regex:/Mongo/}})
db.Articles.find({subject:{$regex:/^Mongo/}})
Query/Feedback