Get output of MongoDB shell script?

MongoDBDatabaseBig Data Analytics

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}];
raja
Published on 02-May-2019 11:22:25
Advertisements