Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Write to MongoDB Console in JavaScript Execution



To write on console, you need to use print() method. The syntax is as follows −

print(“yourString”);

To display objects, you can use printjson(). The syntax is as follows −

printjson(yourObjectName);

Let us implement both the functions. The first query is as follows to display something −

> print("Welcome to MongoDB Console");

The following is the output on a console −

Welcome to MongoDB Console

Let us create an object. The query is as follows −

>studentInformation={"StudentName":"John","StudentAge":24,"StudentTechnicalSkills":["C","C++","Java","MongoDB","MySQL"]};
{
   "StudentName" : "John",
   "StudentAge" : 24,
   "StudentTechnicalSkills" : [
      "C",
      "C++",
      "Java",
      "MongoDB",
      "MySQL"
   ]
}

Here is the query to display the above object “studentInformation” −

> printjson(studentInformation);

The following is the output −

{
   "StudentName" : "John",
   "StudentAge" : 24,
   "StudentTechnicalSkills" : [
      "C",
      "C++",
      "Java",
      "MongoDB",
      "MySQL"
   ]
}
Updated on: 2019-07-30T22:30:25+05:30

101 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements