
- 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
Get output of MongoDB shell script?
You can use printjson() or print() to get output of MongoDB shell script. Let us create an array of objects.
Following is the query to create an array of objects.
> var studentDetails=[{"StudentName":"John","StudentAge":21}, {"StudentName":"Carol","StudentAge":24},{"StudentName":"David","StudentAge":25}];
Following is the query to get the output of Mongo shell script using printjson() −
> printjson(studentDetails);
This will produce the following output −
[ { "StudentName" : "John", "StudentAge" : 21 }, { "StudentName" : "Carol", "StudentAge" : 24 }, { "StudentName" : "David", "StudentAge" : 25 } ] > var studentDetails=[{"StudentName":"John","StudentAge":21}, {"StudentName":"Carol","StudentAge":24},{"StudentName":"David","StudentAge":25}];
- Related Articles
- Use result from MongoDB in shell script?
- How to terminate a MongoDB shell script earlier?
- What is Shell Script?
- Aborting a shell script on any command fails
- How to get items with a specific value from documents using MongoDB shell?
- Running a Shell Script on a Remote Machine Through SSH
- Showing a GUI Notification From a Shell Script in Linux
- Storing a Command in a Variable in a Shell Script
- Prettyprint in MongoDB shell as default?
- Format date value in MongoDB shell?
- Deleting all records of a collection in MongoDB Shell?
- How to print results of script in MongoDB?
- Program to print its script name as output using Python
- Program to print its script name as output in Python
- Inserting Date() in MongoDB through Mongo shell?

Advertisements