
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
MongoDB query to display documents with a specific name irrespective of case
For this, use $regex in MongoDB. We will search for document field value with name “David”, irrespective of case. Let us create a collection with documents −
> db.demo700.insertOne( { details: [ { Name:"david" }]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea6e6b1551299a9f98c93ac") } > db.demo700.insertOne( { details: [ { Name:"Chris" }]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea6e6b9551299a9f98c93ad") } > db.demo700.insertOne( { details: [ { Name:"DAVID" }]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea6e6bf551299a9f98c93ae") } > db.demo700.insertOne( { details: [ { Name:"David" }]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea6e6c4551299a9f98c93af") }
Display all documents from a collection with the help of find() method −
> db.demo700.find();
This will produce the following output −
{ "_id" : ObjectId("5ea6e6b1551299a9f98c93ac"), "details" : [ { "Name" : "david" } ] } { "_id" : ObjectId("5ea6e6b9551299a9f98c93ad"), "details" : [ { "Name" : "Chris" } ] } { "_id" : ObjectId("5ea6e6bf551299a9f98c93ae"), "details" : [ { "Name" : "DAVID" } ] } { "_id" : ObjectId("5ea6e6c4551299a9f98c93af"), "details" : [ { "Name" : "David" } ] }
Following is the query to display documents with a specific name irrespective of case −
> db.demo700.find({"details.Name":{$regex:/^David$/i}});
This will produce the following output −
{ "_id" : ObjectId("5ea6e6b1551299a9f98c93ac"), "details" : [ { "Name" : "david" } ] } { "_id" : ObjectId("5ea6e6bf551299a9f98c93ae"), "details" : [ { "Name" : "DAVID" } ] } { "_id" : ObjectId("5ea6e6c4551299a9f98c93af"), "details" : [ { "Name" : "David" } ] }
- Related Articles
- MongoDB query for documents matching array, irrespective of elements order
- MongoDB query to find documents with specific FirstName and LastName
- MongoDB query to match documents with array values greater than a specific value
- MongoDB query to implement nor query to fetch documents except a specific document
- MongoDB query to update all documents matching specific IDs
- MongoDB inverse of query to return all items except specific documents?
- MongoDB query for specific case insensitive search
- MongoDB query to add up the values of a specific field in documents
- MongoDB query to fetch a specific document rom documents with field value set using NumberInt()?
- MongoDB query to group records and display a specific value with dot notation
- How to find MongoDB documents with a specific string?
- Display only the employee names with specific salaries in MongoDB documents with employee records?
- MongoDB query to get only specific fields in nested array documents?
- MongoDB query to display alternative documents with mapReduce() function and emit even field values
- Restrict returned data in MongoDB to display only specific values from documents

Advertisements