Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print object in mongo script

Tags:

How can I print to console an object in a Mongo script?

I tried:

> print({}) [object Object] 

It simply displays [object Object]. Which is the alternative for console.dir()?

like image 451
Ionică Bizău Avatar asked Sep 18 '13 15:09

Ionică Bizău


2 Answers

You can use printjson for that:

> printjson({}) { }  > printjson({a: 'foo', b: 'bar'}) { "a" : "foo", "b" : "bar" } 
like image 66
JohnnyHK Avatar answered Mar 16 '23 01:03

JohnnyHK


If all I want to do is take a look at the contents, I'll usually just use JSON.stringify().

> print ( JSON.stringify( { "foo": { "bar": "spam" } } ) ) 
like image 20
Lix Avatar answered Mar 16 '23 01:03

Lix