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}];

Updated on: 30-Jul-2019

692 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements