
- 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 do I get email-id from a MongoDB document and display with print()
For this, use forEach() along with print() to display the email-id values. Let us create a collection with documents −
> db.demo690.insertOne({"UserName":"John","UserEmailId":"John@gmail.com"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea6db31551299a9f98c939c") } > db.demo690.insertOne({"UserName":"Bob","UserEmailId":"Bob@gmail.com"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea6db3c551299a9f98c939d") } > db.demo690.insertOne({"UserName":"David","UserEmailId":"David@gmail.com"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea6db47551299a9f98c939e") }
Display all documents from a collection with the help of find() method −
> db.demo690.find();
This will produce the following output −
{ "_id" : ObjectId("5ea6db31551299a9f98c939c"), "UserName" : "John", "UserEmailId" : "John@gmail.com" } { "_id" : ObjectId("5ea6db3c551299a9f98c939d"), "UserName" : "Bob", "UserEmailId" : "Bob@gmail.com" } { "_id" : ObjectId("5ea6db47551299a9f98c939e"), "UserName" : "David", "UserEmailId" : "David@gmail.com" }
Following is the query to get email-id from a MongoDB document and print using print() −
> db.demo690.find().forEach(function(document) { ... print(document.UserEmailId); ... });
This will produce the following output −
John@gmail.com Bob@gmail.com David@gmail.com
- Related Articles
- Update a MongoDB document with Student Id and Name
- How do I delete array value from a document in MongoDB?
- How do I remove a string from an array in a MongoDB document?
- Display MongoDB with document and subdocument example and update
- How to prevent MongoDB from returning the object ID while finding a document?
- How to get id from tr tag and display it in a new td with JavaScript?
- MongoDB query select and display only a specific field from the document?
- Iterate a cursor and print a document in MongoDB?
- How to get element with max id in MongoDB?
- How to reach subdata in MongoDB and display a particular document?
- Get the top most document from a MongoDB collection
- How do I display a list of objects based on a specific property with MongoDB?
- How do I display the indexes of a collection in MongoDB?
- How to print document value in MongoDB shell?
- Display the undefined and exact MongoDB document records

Advertisements