- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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