
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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" }
Advertisements