Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
649 views
in Technique[技术] by (71.8m points)

mongodb - 如何列出mongo shell中的所有集合?(How to list all collections in the mongo shell?)

在MongoDB shell中,如何列出我正在使用的当前数据库的所有集合?

  ask by coffee-grinder translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can do...

(你可以做...)

JS (shell):

(JS(shell):)

db.getCollectionNames()

node.js:

(Node.js的:)

db.listCollections()

non-JS (shell only):

(非JS(仅限shell):)

show collections

The reason I call that non-JS is because:

(我称之为非JS的原因是:)

$ mongo prodmongo/app --eval "show collections"
MongoDB shell version: 3.2.10
connecting to: prodmongo/app
2016-10-26T19:34:34.886-0400 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell eval):1:5

$ mongo prodmongo/app --eval "db.getCollectionNames()"
MongoDB shell version: 3.2.10
connecting to: prodmongo/app
[
    "Profiles",
    "Unit_Info"
]

If you really want that sweet, sweet show collections output, you can:

(如果你真的想要甜蜜,甜蜜的show collections输出,你可以:)

$ mongo prodmongo/app --eval "db.getCollectionNames().join('
')"
MongoDB shell version: 3.2.10
connecting to: prodmongo/app
Profiles
Unit_Info

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...