Use printjson() to output Objects in MongoDB shell

Tadashi Shigeoka ·  Sat, March 19, 2016

If you want to output Objects in MongoDB shell, you can’t output with print(), so use printjson().

MongoDB | モンゴディービー

Below are sample execution results of Object with print() and printjson().

> var object = { a : 1 , b : 2 };

> print(object);
[object Object]

> printjson(object);
{ "a" : 1, "b" : 2 }

> printjson(1)
1
> printjson("a")
"a"

In most cases, it’s probably good to use printjson().

Reference Information

That’s all from the Gemba.