[SERVER-4371] pretty print when find returns one result Created: 24/Nov/11  Updated: 29/Feb/12  Resolved: 25/Nov/11

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.0.1
Fix Version/s: None

Type: Improvement Priority: Trivial - P5
Reporter: Grégoire Seux Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: shell
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

It would be nice to have a more pretty print version of find results when there are only a few of them. Instead of inlining results, it could look like findOne output.

I understand that some would like to keep this inlining so it should be optionnal (in .mongorc.js ?)



 Comments   
Comment by Scott Hernandez (Inactive) [ 25/Nov/11 ]

Yeah, I will add docs for that when you do: db.coll.find().help()

Comment by Grégoire Seux [ 25/Nov/11 ]

I think the use of
db.url.find().pretty() is what I was looking for.

Comment by Scott Hernandez (Inactive) [ 24/Nov/11 ]

You can get the results you want using the printjson function, and converting the cursor to an array:

> db.url_hits.find()
{ "_id" : "/contact", "agents" : { "agent1" : 2 }, "views" : 3 }
{ "_id" : "/home", "agents" : { "agent1" : 4, "agent2" : 1, "agent3" : 2 }, "views" : 9 }
 
> printjson(db.url_hits.find().limit(5).toArray())
[
	{
		"_id" : "/contact",
		"agents" : {
			"agent1" : 2
		},
		"views" : 3
	},
	{
		"_id" : "/home",
		"agents" : {
			"agent1" : 4,
			"agent2" : 1,
			"agent3" : 2
		},
		"views" : 9
	}
]

Generated at Thu Feb 08 03:05:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.