Is there any way to see the mongo results in a better format, like we are using \G in the sql ?
Asked
Active
Viewed 665 times
2 Answers
6
There is no way to enable vertical printing like what you would see in \G in MySQL. In the context that view is less useful, since MongoDB is a document store and can have nested documents and the like.
You can print out the results of a query in pretty printing, by adding a .pretty()
to the query:
db.test.find().pretty()
Which will return the results in a expanded document view, which may be helpful.

Andre de Frere
- 2,703
- 16
- 13
2
In addition to @Andre solution, in case you want to get only one element. You can use findOne function. It pretty prints that document.
db.test.findOne()
Also you can use toArray over a cursor. Though its a memory hog, but for small number of results its fine and pretty prints,
db.test.find({...}).toArray()

Sushant Gupta
- 8,980
- 5
- 43
- 48