Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to print to console an object in a MongoDB script?
You can use printjson() method to print to console an object in a MongoDB script. The syntax is as follows −
printjson({yourFieldName”:yourValue”,........N});
You can use JSON.stringify() along with print() function. The syntax is as follows minus;
print ( JSON.stringify( { {yourFieldName”:yourValue”,........N} } ));
Let us implement the above syntax to print object in Mongo script. The query is as follows −
>printjson({"UserId":101,"UserName":"John","UserCoreSuject":["Java","MongoDB","MySQL","SQL Server"]});
The following is the output −
{
"UserId" : 101,
"UserName" : "John",
"UserCoreSuject" : [
"Java",
"MongoDB",
"MySQL",
"SQL Server"
]
}
You can use another query −
> print ( JSON.stringify( {"UserId":101,"UserName":"John","UserCoreSuject":["Java","MongoDB","MySQL","SQL Server"]} ));
The following is the output −
{"UserId":101,"UserName":"John","UserCoreSuject":["Java","MongoDB","MySQL","SQL Server"]} Advertisements
