
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Text search in MongoDB with Regular Expression
For text search in MongoDB with Regular Expression, use $regex. Let us create a collection with documents −
> db.demo519.insertOne({"Value":"50,60,70"});{ "acknowledged" : true, "insertedId" : ObjectId("5e88b9c0b3fbf26334ef6111") } > db.demo519.insertOne({"Value":"80,90,50"});{ "acknowledged" : true, "insertedId" : ObjectId("5e88b9c7b3fbf26334ef6112") } > db.demo519.insertOne({"Value":"10,30,40"});{ "acknowledged" : true, "insertedId" : ObjectId("5e88b9cfb3fbf26334ef6113") }
Display all documents from a collection with the help of find() method −
> db.demo519.find();
This will produce the following output −
{ "_id" : ObjectId("5e88b9c0b3fbf26334ef6111"), "Value" : "50,60,70" } { "_id" : ObjectId("5e88b9c7b3fbf26334ef6112"), "Value" : "80,90,50" } { "_id" : ObjectId("5e88b9cfb3fbf26334ef6113"), "Value" : "10,30,40" }
Following is the query to implement text search in MongoDB with Regex −
> db.demo519.findOne({ Value: { $regex: /50/ } });
This will produce the following output −
{ "_id" : ObjectId("5e88b9c0b3fbf26334ef6111"), "Value" : "50,60,70" }
- Related Questions & Answers
- Explain Python regular expression search vs match
- Using a regex with text search in MongoDB
- Implement Text search in MongoDB
- Perform MongoDB full text search
- Regular Expression in C# with Examples
- Regular Expression in Python with Examples?
- MongoDB regular expression to match a specific record?
- MongoDB: Find name similar to Regular Expression input?
- Select query with regular expression in MySQL
- Create an index for text search in MongoDB
- How to extract numbers from text using Python regular expression?
- How to extract date from text using Python regular expression?
- Explain JavaScript Regular Expression modifiers with examples
- Search and Replace with Java regular expressions
- How to extract floating number from text using Python regular expression?
Advertisements