-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Server
-
Labels:None
The documentation page on Write Scripts for the mongo Shell mentions that you cannot include use <dbname> inside a JavaScript file, but does not have a full list of equivalent JS for other interactive helpers such as "show dbs".
We should include a table mapping these, for example:
Shell helper | JavaScript equivalent |
---|---|
show dbs | db.adminCommand('listDatabases') |
show collections | db.getCollectionNames() |
show users | db.system.users.find() |
show log <logname> | db.adminCommand(
{'getLog': '<logname>'}
) |
use <db_name> | db.getSiblingDB('<db_name>') |
It is also worth noting that in non-interactive mode (i.e. --eval) these commands will return the corresponding JavaScript data, but will not display any output. The printjson() function can be used to display the results of a JavaScript function, for example: printjson(db.adminCommand('listDatabases')).
This should probably also be cross-referenced from Running .js files via a mongo shell Instance on the Server.
- related to
-
SERVER-6237 Shell helpers should document the analogous JS bindings
- Backlog