หากต้องการเขียนบนคอนโซล คุณต้องใช้วิธี 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"
]
}