Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Samual Sam

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

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.