Du kan göra...
JavaScript (skal):
db.getCollectionNames()
Node.js:
db.listCollections()
Icke-JavaScript (endast skal):
show collections
Anledningen till att jag kallar det icke-JavaScript är att:
$ 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"
]
Om du verkligen vill ha den söta, söta show collections
utdata kan du:
$ mongo prodmongo/app --eval "db.getCollectionNames().join('\n')"
MongoDB shell version: 3.2.10
connecting to: prodmongo/app
Profiles
Unit_Info