Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-1595

Table listing JS equivalents of non-JS shell helpers

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • Server_Docs_20231030
    • 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.

            Assignee:
            allison.moore@mongodb.com Allison Reinheimer Moore
            Reporter:
            stephen.steneker@mongodb.com Stennie Steneker (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              10 years, 46 weeks, 5 days ago