
- 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
Finding a MongoDB document through a word
To find a MongoDB document through a word, use find() and set the word like −
word/i
Let us create a collection with documents −
> db.demo212.insertOne({"details":[{"Name":"John Doe"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e2c7603d395bdc21346ff") } > db.demo212.insertOne({"details":[{"Name":"Chris Brown"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e2c8003d395bdc2134700") } > db.demo212.insertOne({"details":[{"Name":"Robert doe"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e2c8a03d395bdc2134701") }
Display all documents from a collection with the help of find() method −
> db.demo212.find();
This will produce the following output −
{ "_id" : ObjectId("5e3e2c7603d395bdc21346ff"), "details" : [ { "Name" : "John Doe" } ] } { "_id" : ObjectId("5e3e2c8003d395bdc2134700"), "details" : [ { "Name" : "Chris Brown" } ] } { "_id" : ObjectId("5e3e2c8a03d395bdc2134701"), "details" : [ { "Name" : "Robert doe" } ] }
Following is the query to find a MongoDB document through a word −
> db.demo212.find({"details.Name":/doe/i});
This will produce the following output −
{ "_id" : ObjectId("5e3e2c7603d395bdc21346ff"), "details" : [ { "Name" : "John Doe" } ] } { "_id" : ObjectId("5e3e2c8a03d395bdc2134701"), "details" : [ { "Name" : "Robert doe" } ] }
- Related Articles
- How to prevent MongoDB from returning the object ID while finding a document?
- Finding second smallest word in a string - JavaScript
- Finding shortest word in a string in JavaScript
- Extract a MongoDB document with a specific string
- Find a document with ObjectID in MongoDB?
- How to delete a document in MongoDB?
- Update only a single document in MongoDB
- Remove only a single document in MongoDB
- MongoDB findOneAndUpdate() to update a single document
- Get array items inside a MongoDB document?
- MongoDB query to remove a specific document
- Filter specific values from a MongoDB document
- Finding the longest word in a string in JavaScript
- How to Convert an Excel File to a Word Document?
- Iterate a cursor and print a document in MongoDB?

Advertisements