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

Table listing JS equivalents of non-JS shell helpers

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • Server_Docs_20231030
    • None
    • Server
    • None

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:
              10 years, 32 weeks, 1 day ago