要在控制台上编写,您需要使用print()
方法。语法如下-
print(“yourString”);
要显示对象,可以使用printjson()
。语法如下-
printjson(yourObjectName);
让我们实现这两个功能。第一个查询如下所示以显示某些内容-
> print("Welcome to MongoDB Console");
以下是控制台上的输出-
Welcome to MongoDB Console
让我们创建一个对象。查询如下-
>studentInformation={"StudentName":"John","StudentAge":24,"StudentTechnicalSkills":["C","C++","Java","MongoDB","MySQL"]}; { "StudentName" : "John", "StudentAge" : 24, "StudentTechnicalSkills" : [ "C", "C++", "Java", "MongoDB", "MySQL" ] }
这是显示上述对象“ studentInformation”的查询-
> printjson(studentInformation);
以下是输出-
{ "StudentName" : "John", "StudentAge" : 24, "StudentTechnicalSkills" : [ "C", "C++", "Java", "MongoDB", "MySQL" ] }