
- 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
MongoDB query to search for string like “@email” in the field values
Search for email string using MongoDB find(). Let us create a collection with documents −
> db.demo727.insertOne({UserId:"John@email.com"}); { "acknowledged" : true, "insertedId" : ObjectId("5eab375f43417811278f5898") } > db.demo727.insertOne({UserId:"John@yahoo.com"}); { "acknowledged" : true, "insertedId" : ObjectId("5eab376043417811278f5899") } > db.demo727.insertOne({UserId:"Chris@EMAIL.com"}); { "acknowledged" : true, "insertedId" : ObjectId("5eab376143417811278f589a") }
Display all documents from a collection with the help of find() method −
> db.demo727.find();
This will produce the following output −
{ "_id" : ObjectId("5eab375f43417811278f5898"), "UserId" : "John@email.com" } { "_id" : ObjectId("5eab376043417811278f5899"), "UserId" : "John@yahoo.com" } { "_id" : ObjectId("5eab376143417811278f589a"), "UserId" : "Chris@EMAIL.com" }
Following is the query to search for @email like string −
> db.demo727.find({"UserId":/@email/i});
This will produce the following output −
{ "_id" : ObjectId("5eab375f43417811278f5898"), "UserId" : "John@email.com" } { "_id" : ObjectId("5eab376143417811278f589a"), "UserId" : "Chris@EMAIL.com" }
- Related Questions & Answers
- How to query MongoDB with “like”?
- Query MongoDB with “like” implementation on name and email field beginning with a specific letter?
- How to query MongoDB similar to “like” ?
- MongoDB Query for boolean field as “not true”
- “Toggle” query in MongoDB?
- MongoDB query to fetch only the “Name” field based on roles?
- What is the equivalent of SQL “like” in MongoDB?
- “Structured” grouping query in MongoDB to display result with a new field displaying the count
- MySQL query to convert a string like “1h 15 min” into 75 minutes?
- Can we use “LIKE concat()” in a MySQL query?
- MongoDB: How to query a collection named “version”?
- How to search for string or number in a field with MongoDB?
- How to search for “ñ” and avoid records that include “n” in MySQL?
- MySQL database field type for search query?
- MongoDB query for ranking / search count?
Advertisements