您可以使用printjson()
方法来打印以在MongoDB脚本中控制台对象。语法如下-
printjson({yourFieldName”:yourValue”,........N});
您可以将JSON.stringify()与print()
函数一起使用。语法如下:
print ( JSON.stringify( { {yourFieldName”:yourValue”,........N} } ));
让我们实现以上语法以在Mongo脚本中打印对象。查询如下-
>printjson({"UserId":101,"UserName":"John","UserCoreSuject":["Java","MongoDB","MySQL","SQL Server"]});
以下是输出-
{ "UserId" : 101, "UserName" : "John", "UserCoreSuject" : [ "Java", "MongoDB", "MySQL", "SQL Server" ] }
您可以使用另一个查询-
> print ( JSON.stringify( {"UserId":101,"UserName":"John","UserCoreSuject":["Java","MongoDB","MySQL","SQL Server"]} ));
以下是输出-
{"UserId":101,"UserName":"John","UserCoreSuject":["Java","MongoDB","MySQL","SQL Server"]}