Skip to content

DOCS-1595 adding table mapping helpers to their javascript equivalents #1094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions source/core/server-side-javascript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ administrative work. When you run :program:`mongo` shell on the server,
connecting via the localhost interface, the connection is fast with low
latency.

The :ref:`command helpers <command-helpers>` provided in the
:program:`mongo` shell cannot be used inside JavaScript files because
they are not valid JavaScript. The following table maps the most common
:program:`mongo` shell helpers to their JavaScript equivalents.

.. include:: /includes/table-helpers-to-javascript.rst

Concurrency
-----------

Expand Down
29 changes: 29 additions & 0 deletions source/includes/table-helpers-to-javascript.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. list-table::
:header-rows: 1

* - **Shell Helpers**
- **JavaScript Equivalents**

* - ``show dbs``, ``show databases``

- ``db.adminCommand('listDatabases')``

* - ``use <db>``

- ``db = db.getSiblingDB('<db>')``

* - ``show collections``

- ``db.getCollectionNames()``

* - ``show users``

- ``db.system.users.find()``

* - ``show log <logname>``

- ``db.adminCommand( { 'getLog' : '<logname>' } )``

* - ``show logs``

- ``db.adminCommand( { 'getLog' : '*' } )
12 changes: 9 additions & 3 deletions source/tutorial/write-scripts-for-the-mongo-shell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ non-default port ``27020`` and set the global ``db`` variable:
If you create new connections inside a :ref:`JavaScript file
<mongo-shell-javascript-file>`:

- You **cannot** use ``use <dbname>`` inside the file to set the ``db``
global variable.

- To set the ``db`` global variable, use the :method:`~Mongo.getDB()`
method or the :method:`connect()` method. You can assign the
database reference to a variable other than ``db``.
Expand All @@ -62,6 +59,15 @@ If you create new connections inside a :ref:`JavaScript file
:method:`db.getLastErrorObj()` or :method:`db.getLastError()`
explicitly to wait for the result of :doc:`write
operations</core/write-operations>`.

- You **cannot** use any shell helper (e.g. ``use <dbname>``, ``show
dbs``, etc.) inside the JavaScript file because they are not valid
JavaScript.

The following table maps the most common :program:`mongo` shell
helpers to their JavaScript equivalents.

.. include:: /includes/table-helpers-to-javascript.rst

.. _mongo-shell-scripting:

Expand Down