
- 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
Use result from MongoDB in shell script?
Let us first create a collection with a document −
>db.useResultDemo.insertOne({"StudentFirstName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5cda70f5b50a6c6dd317adcd") }
Display all documents from a collection with the help of find() method −
> db.useResultDemo.find();
Following is the output −
{ "_id" : ObjectId("5cda70f5b50a6c6dd317adcd"), "StudentFirstName" : "Robert" }
Here is the query to use result from MongoDB in shell script with var keyword −
> var studentName=db.useResultDemo.findOne({},{_id:0}); > studentName
Following is the output −
{ "StudentFirstName" : "Robert" }
- Related Articles
- Get output of MongoDB shell script?
- How to terminate a MongoDB shell script earlier?
- Showing a GUI Notification From a Shell Script in Linux
- What is Shell Script?
- How can I use a script to create users in MongoDB?
- Storing a Command in a Variable in a Shell Script
- Aborting a shell script on any command fails
- Can we remove _id from MongoDB query result?
- Identify last document from MongoDB find() result set?
- How to operate on all databases from the MongoDB shell?
- Prettyprint in MongoDB shell as default?
- Format date value in MongoDB shell?
- Inserting Date() in MongoDB through Mongo shell?
- Running a Shell Script on a Remote Machine Through SSH
- How to Count Word Occurrences in a Text File using Shell Script?

Advertisements