MongoDB शेल में आउटपुट प्रिंट करना
MongoDB शेल स्क्रिप्ट का आउटपुट प्राप्त करने के लिए आप printjson() या print() फंक्शन का उपयोग कर सकते हैं।
उदाहरण: ऑब्जेक्ट्स की ऐरे बनाना
> var studentDetails=[{"StudentName":"John","StudentAge":21},
... {"StudentName":"Carol","StudentAge":24},{"StudentName":"David","StudentAge":25}];
printjson() का उपयोग करके आउटपुट प्राप्त करना
> printjson(studentDetails);
आउटपुट:
[
{
"StudentName" : "John",
"StudentAge" : 21
},
{
"StudentName" : "Carol",
"StudentAge" : 24
},
{
"StudentName" : "David",
"StudentAge" : 25
}
]
नोट: printjson() JSON फॉर्मेट में सुंदर आउटपुट देता है, जबकि print() साधारण टेक्स्ट आउटपुट देता है। डिबगिंग के लिए printjson() अधिक उपयोगी है।