From e0089ae5297cd5c8118323f791f8c56e2e9b0c0c Mon Sep 17 00:00:00 2001 From: schmalliso Date: Wed, 19 Jun 2013 17:01:39 -0400 Subject: [PATCH] DOCS-1595 adding table mapping helpers to their javascript equivalents --- source/core/server-side-javascript.txt | 7 +++++ .../includes/table-helpers-to-javascript.rst | 29 +++++++++++++++++++ .../write-scripts-for-the-mongo-shell.txt | 12 ++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 source/includes/table-helpers-to-javascript.rst diff --git a/source/core/server-side-javascript.txt b/source/core/server-side-javascript.txt index 469de0c057a..55a0d1b7ce3 100644 --- a/source/core/server-side-javascript.txt +++ b/source/core/server-side-javascript.txt @@ -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 ` 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 ----------- diff --git a/source/includes/table-helpers-to-javascript.rst b/source/includes/table-helpers-to-javascript.rst new file mode 100644 index 00000000000..b17c8a916ca --- /dev/null +++ b/source/includes/table-helpers-to-javascript.rst @@ -0,0 +1,29 @@ +.. list-table:: + :header-rows: 1 + + * - **Shell Helpers** + - **JavaScript Equivalents** + + * - ``show dbs``, ``show databases`` + + - ``db.adminCommand('listDatabases')`` + + * - ``use `` + + - ``db = db.getSiblingDB('')`` + + * - ``show collections`` + + - ``db.getCollectionNames()`` + + * - ``show users`` + + - ``db.system.users.find()`` + + * - ``show log `` + + - ``db.adminCommand( { 'getLog' : '' } )`` + + * - ``show logs`` + + - ``db.adminCommand( { 'getLog' : '*' } ) diff --git a/source/tutorial/write-scripts-for-the-mongo-shell.txt b/source/tutorial/write-scripts-for-the-mongo-shell.txt index e9dbe9f2b2d..8e1347830fc 100644 --- a/source/tutorial/write-scripts-for-the-mongo-shell.txt +++ b/source/tutorial/write-scripts-for-the-mongo-shell.txt @@ -51,9 +51,6 @@ non-default port ``27020`` and set the global ``db`` variable: If you create new connections inside a :ref:`JavaScript file `: -- You **cannot** use ``use `` 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``. @@ -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`. + +- You **cannot** use any shell helper (e.g. ``use ``, ``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: