
- 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
How to make a case-insensitive query in MongoDB?
For a case-insensitive query, use regex in MongoDB. Let us create a collection with documents −
> db.demo314.insertOne({"Name":"Chris brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5e50d742f8647eb59e562056") } > db.demo314.insertOne({"Name":"David Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5e50d743f8647eb59e562057") } > db.demo314.insertOne({"Name":"CHRIS BROWN"}); { "acknowledged" : true, "insertedId" : ObjectId("5e50d744f8647eb59e562058") } > db.demo314.insertOne({"Name":"DAVID MILLER"}); { "acknowledged" : true, "insertedId" : ObjectId("5e50d747f8647eb59e562059") } > db.demo314.insertOne({"Name":"chris brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5e50d749f8647eb59e56205a") }
Display all documents from a collection with the help of find() method −
> db.demo314.find();
This will produce the following output −
{ "_id" : ObjectId("5e50d742f8647eb59e562056"), "Name" : "Chris brown" } { "_id" : ObjectId("5e50d743f8647eb59e562057"), "Name" : "David Miller" } { "_id" : ObjectId("5e50d744f8647eb59e562058"), "Name" : "CHRIS BROWN" } { "_id" : ObjectId("5e50d747f8647eb59e562059"), "Name" : "DAVID MILLER" } { "_id" : ObjectId("5e50d749f8647eb59e56205a"), "Name" : "chris brown" }
Following is the query to make a case-insensitive query. This displays “chris brown” name available in every possible case in the document −
> db.demo314.find({"Name":/chris brown/i});
This will produce the following output −
{ "_id" : ObjectId("5e50d742f8647eb59e562056"), "Name" : "Chris brown" } { "_id" : ObjectId("5e50d744f8647eb59e562058"), "Name" : "CHRIS BROWN" } { "_id" : ObjectId("5e50d749f8647eb59e56205a"), "Name" : "chris brown" }
- Related Articles
- Is it possible to make a case-insensitive query in MongoDB?
- MongoDB query with case insensitive search?
- MongoDB query for specific case insensitive search
- How do I make case-insensitive queries on MongoDB?
- How to make jQuery attribute selector case insensitive?
- How do I make my string comparison case insensitive?
- How do we make my string comparison case insensitive in java?
- How to use case-insensitive switch-case in JavaScript?
- How to perform case-insensitive search in Oracle?
- MongoDB $regex operator i or I for case insensitive search
- How to achieve case sensitive uniqueness and case insensitive search in MySQL?
- Case insensitive search in Mongo?
- Case-insensitive Dictionary in C#
- MySQL case-insensitive DISTINCT?
- Is Python case-sensitive or case-insensitive?

Advertisements