How to print out more than 20 items (documents) in MongoDB's shell?
db.foo.find().limit(300)
won't do it. It still prints out only 20 documents.
db.foo.find().toArray()
db.foo.find().forEach(printjson)
will both print out very expanded view of each document instead of the 1-line version for find():
Could always do:
db.foo.find().forEach(function(f){print(tojson(f, '', true));});
To get that compact view.
Also, I find it very useful to limit the fields returned by the find so:
db.foo.find({},{name:1}).forEach(function(f){print(tojson(f, '', true));});
which would return only the _id and name field from foo.
本文介绍了如何在MongoDB shell中查询超过20项的方法,包括使用forEach结合tojson来获取紧凑视图,并展示了如何限制返回字段以提高查询效率。
1699

被折叠的 条评论
为什么被折叠?



