From e998407ee71ebf78bfc6bf3ebd9e98ae8c6dac2e Mon Sep 17 00:00:00 2001 From: kay Date: Fri, 8 Feb 2013 16:47:56 -0500 Subject: [PATCH 1/2] DOCS-963 add Mongo(), connect() methods --- source/reference/method/Mongo.getDB.txt | 22 ++++++++++++ source/reference/method/Mongo.txt | 35 +++++++++++++++++++ source/reference/method/connect.txt | 23 ++++++++++++ .../write-scripts-for-the-mongo-shell.txt | 31 +++++++++------- 4 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 source/reference/method/Mongo.getDB.txt create mode 100644 source/reference/method/Mongo.txt create mode 100644 source/reference/method/connect.txt diff --git a/source/reference/method/Mongo.getDB.txt b/source/reference/method/Mongo.getDB.txt new file mode 100644 index 00000000000..3bad427a2b4 --- /dev/null +++ b/source/reference/method/Mongo.getDB.txt @@ -0,0 +1,22 @@ +============= +Mongo.getDB() +============= + +.. default-domain:: mongodb + +.. method:: Mongo.getDB() + + Use the :method:`Mongo.getDB()` method to access the database from + the :program:`mongo` shell or from a JavaScript file. The + :method:`~Mongo.getDB()` method accepts a string ```` + parameter. + + The following example instantiates a new connection to the MongoDB + instance running on the localhost interface and sets the + current db to ``"myDatabase"``: + + .. code-block:: javascript + + db = new Mongo().getDB("myDatabase") + + .. seealso:: :method:`Mongo()`, :doc:`/reference/method/connect` diff --git a/source/reference/method/Mongo.txt b/source/reference/method/Mongo.txt new file mode 100644 index 00000000000..77bfb1d52e5 --- /dev/null +++ b/source/reference/method/Mongo.txt @@ -0,0 +1,35 @@ +======= +Mongo() +======= + +.. default-domain:: mongodb + +.. method:: Mongo() + + JavaScript constructor to instantiate a database connection from the + :program:`mongo` shell or from a JavaScript file. + + The constructor can take: + + - no parameters to instantiate a connection to the localhost + interface on the default port: + + .. code-block:: javascript + + new Mongo() + + - a string ```` parameter to instantiate a connection to the + ```` and the default port: + + .. code-block:: javascript + + new Mongo() + + - a string ```` parameter to instantiate a connection to + the ```` and the ````: + + .. code-block:: javascript + + new Mongo() + + .. seealso:: :method:`Mongo.getDB()` diff --git a/source/reference/method/connect.txt b/source/reference/method/connect.txt new file mode 100644 index 00000000000..32b83d67411 --- /dev/null +++ b/source/reference/method/connect.txt @@ -0,0 +1,23 @@ +========= +connect() +========= + +.. default-domain:: mongodb + +.. method:: connect( ) + + Use the :method:`connect()` method to access the database from the + :program:`mongo` shell or from a JavaScript file. The method accepts + a string ``/database`` parameter to connect to the + MongoDB instance on the ```` and return the reference + to the database ````. + + The following example instantiates a new connection to the MongoDB + instance running on the localhost interface and sets the + current db to ``myDatabase``: + + .. code-block:: javascript + + db = connect("localhost:27017/myDatabase") + + .. seealso:: :method:`Mongo.getDB()` diff --git a/source/tutorial/write-scripts-for-the-mongo-shell.txt b/source/tutorial/write-scripts-for-the-mongo-shell.txt index 6611f6e7625..dd7bc181c87 100644 --- a/source/tutorial/write-scripts-for-the-mongo-shell.txt +++ b/source/tutorial/write-scripts-for-the-mongo-shell.txt @@ -20,7 +20,8 @@ Opening New Connections ----------------------- From the :program:`mongo` shell or from a JavaScript file, you can -instantiate database connections using the ``Mongo()`` constructor: +instantiate database connections using the :method:`MongoDB()` +constructor: .. code-block:: javascript @@ -30,29 +31,35 @@ instantiate database connections using the ``Mongo()`` constructor: Consider the following example that instantiates a new connection to the MongoDB instance running on localhost on the default port and sets -the current ``db`` to ``myDatabase`` using the ``getDB()`` method: +the current ``db`` to ``myDatabase`` using the :method:`Mongo.getDB()` +method: .. code-block:: javascript conn = new Mongo(); db = conn.getDB("myDatabase"); -Additionally, you can use the ``connect()`` method to connect to the -MongoDB instance. The following example connects to the MongoDB -instance that is running on ``localhost`` with the non-default port -``207020`` and set the current ``db``: +Additionally, you can use the :doc:`/reference/method/connect` method +to connect to the MongoDB instance. The following example connects to +the MongoDB instance that is running on ``localhost`` with the +non-default port ``27020`` and set the current ``db``: .. code-block:: javascript db = connect("localhost:27020/myDatabase"); If you create new connections inside a :ref:`JavaScript file -`, you must assign the ``db`` variable -using the ``getDB()`` method or the ``connect()`` method. You -**cannot** use ``use `` inside the file. Additionally, inside -the script, you would need to call :method:`db.getLastErrorObj()` or -:method:`db.getLastError()` explicitly to wait for the result of -:doc:`write operations`. +`: + +- You must assign the ``db`` variable using the :method:`Mongo.getDB()` + method or the :doc:`/reference/method/connect` method. + +- You **cannot** use ``use `` inside the file. + +- Additionally, inside the script, you would need to call + :method:`db.getLastErrorObj()` or :method:`db.getLastError()` + explicitly to wait for the result of :doc:`write + operations`. .. _mongo-shell-scripting: From 9312f10350fb2adfb3ce7d9a1452c4fb5afa07e7 Mon Sep 17 00:00:00 2001 From: kay Date: Tue, 12 Feb 2013 11:31:33 -0500 Subject: [PATCH 2/2] DOCS-963 add Mongo, getDB and connect methods --- source/reference/method/Mongo.getDB.txt | 16 +++++----- source/reference/method/Mongo.txt | 29 +++++++------------ source/reference/method/connect.txt | 19 +++++++----- .../write-scripts-for-the-mongo-shell.txt | 18 +++++++----- 4 files changed, 40 insertions(+), 42 deletions(-) diff --git a/source/reference/method/Mongo.getDB.txt b/source/reference/method/Mongo.getDB.txt index 3bad427a2b4..caf42eb7d5e 100644 --- a/source/reference/method/Mongo.getDB.txt +++ b/source/reference/method/Mongo.getDB.txt @@ -4,19 +4,19 @@ Mongo.getDB() .. default-domain:: mongodb -.. method:: Mongo.getDB() +.. method:: Mongo.getDB() Use the :method:`Mongo.getDB()` method to access the database from - the :program:`mongo` shell or from a JavaScript file. The - :method:`~Mongo.getDB()` method accepts a string ```` - parameter. + the :program:`mongo` shell or from a JavaScript file. + + :param string database: The name of the database to access. The following example instantiates a new connection to the MongoDB - instance running on the localhost interface and sets the - current db to ``"myDatabase"``: + instance running on the localhost interface and returns a reference + to ``"myDatabase"``: .. code-block:: javascript - db = new Mongo().getDB("myDatabase") + db = new Mongo().getDB("myDatabase"); - .. seealso:: :method:`Mongo()`, :doc:`/reference/method/connect` + .. seealso:: :method:`Mongo()` and :doc:`/reference/method/connect` diff --git a/source/reference/method/Mongo.txt b/source/reference/method/Mongo.txt index 77bfb1d52e5..b37f9a8137d 100644 --- a/source/reference/method/Mongo.txt +++ b/source/reference/method/Mongo.txt @@ -9,27 +9,20 @@ Mongo() JavaScript constructor to instantiate a database connection from the :program:`mongo` shell or from a JavaScript file. - The constructor can take: + :param string host: - - no parameters to instantiate a connection to the localhost - interface on the default port: + Optional. Either in the form of ```` or + ``:``. - .. code-block:: javascript + - Pass the ```` parameter to the constructor to + instantiate a connection to the ```` and the default + port. - new Mongo() + - Pass the ``:`` parameter to the constructor to + instantiate a connection to the ```` and the + ````. - - a string ```` parameter to instantiate a connection to the - ```` and the default port: - - .. code-block:: javascript - - new Mongo() - - - a string ```` parameter to instantiate a connection to - the ```` and the ````: - - .. code-block:: javascript - - new Mongo() + Use the constructor without a parameter to instantiate a + connection to the localhost interface on the default port. .. seealso:: :method:`Mongo.getDB()` diff --git a/source/reference/method/connect.txt b/source/reference/method/connect.txt index 32b83d67411..c37f0280cb1 100644 --- a/source/reference/method/connect.txt +++ b/source/reference/method/connect.txt @@ -4,17 +4,20 @@ connect() .. default-domain:: mongodb -.. method:: connect( ) +.. method:: connect( :/ ) - Use the :method:`connect()` method to access the database from the - :program:`mongo` shell or from a JavaScript file. The method accepts - a string ``/database`` parameter to connect to the - MongoDB instance on the ```` and return the reference - to the database ````. + The :method:`connect()` method creates a connection to a MongoDB instance. + However, use the :method:`Mongo()` object and its + :method:`~Mongo.getDB()` method in most cases. + + :method:`connect()` accepts a string ``:/`` + parameter to connect to the MongoDB instance on the + ``:`` and return the reference to the database + ````. The following example instantiates a new connection to the MongoDB - instance running on the localhost interface and sets the - current db to ``myDatabase``: + instance running on the localhost interface and returns a reference + to ``myDatabase``: .. code-block:: javascript diff --git a/source/tutorial/write-scripts-for-the-mongo-shell.txt b/source/tutorial/write-scripts-for-the-mongo-shell.txt index dd7bc181c87..558af32048b 100644 --- a/source/tutorial/write-scripts-for-the-mongo-shell.txt +++ b/source/tutorial/write-scripts-for-the-mongo-shell.txt @@ -20,7 +20,7 @@ Opening New Connections ----------------------- From the :program:`mongo` shell or from a JavaScript file, you can -instantiate database connections using the :method:`MongoDB()` +instantiate database connections using the :method:`Mongo()` constructor: .. code-block:: javascript @@ -31,18 +31,18 @@ constructor: Consider the following example that instantiates a new connection to the MongoDB instance running on localhost on the default port and sets -the current ``db`` to ``myDatabase`` using the :method:`Mongo.getDB()` -method: +the global ``db`` variable to ``myDatabase`` using the +:method:`~Mongo.getDB()` method: .. code-block:: javascript conn = new Mongo(); db = conn.getDB("myDatabase"); -Additionally, you can use the :doc:`/reference/method/connect` method +Additionally, you can use the :method:`connect()` method to connect to the MongoDB instance. The following example connects to the MongoDB instance that is running on ``localhost`` with the -non-default port ``27020`` and set the current ``db``: +non-default port ``27020`` and set the global ``db`` variable: .. code-block:: javascript @@ -51,10 +51,12 @@ non-default port ``27020`` and set the current ``db``: If you create new connections inside a :ref:`JavaScript file `: -- You must assign the ``db`` variable using the :method:`Mongo.getDB()` - method or the :doc:`/reference/method/connect` method. +- You **cannot** use ``use `` inside the file to set the ``db`` + global variable. -- You **cannot** use ``use `` inside the file. +- To set the ``db`` global variable, use the :method:`~Mongo.getDB()` + method or the :method:`connect()` method. You can, of + course, assign the database reference to a variable other than ``db``. - Additionally, inside the script, you would need to call :method:`db.getLastErrorObj()` or :method:`db.getLastError()`