From b5c42f9ef249beef48419a9421f981371c95a1c6 Mon Sep 17 00:00:00 2001 From: kay Date: Mon, 7 Jan 2013 13:48:39 -0500 Subject: [PATCH 1/4] DOCS-853 toArray method --- source/core/read-operations.txt | 14 ++++++----- source/reference/method/cursor.toArray.txt | 28 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 source/reference/method/cursor.toArray.txt diff --git a/source/core/read-operations.txt b/source/core/read-operations.txt index 563f7f0ee6b..5e893206916 100644 --- a/source/core/read-operations.txt +++ b/source/core/read-operations.txt @@ -732,9 +732,9 @@ information on cursor methods. Iterator Index ~~~~~~~~~~~~~~ -In the :program:`mongo` shell, you can use the ``toArray()`` method to -iterate the cursor and return the documents in an array, as in the -following: +In the :program:`mongo` shell, you can use the :method:`toArray() +` method to iterate the cursor and return the +documents in an array, as in the following: .. code-block:: javascript @@ -742,13 +742,15 @@ following: var documentArray = myCursor.toArray(); var myDocument = documentArray[3]; -The ``toArray()`` method loads into RAM all documents returned by the -cursor; the ``toArray()`` method exhausts the cursor. +The :method:`toArray() ` method loads into RAM all +documents returned by the cursor; the :method:`toArray() +` method exhausts the cursor. Additionally, some :doc:`drivers ` provide access to the documents by using an index on the cursor (i.e. ``cursor[index]``). This is a shortcut for first calling the -``toArray()`` method and then using an index on the resulting array. +:method:`toArray() ` method and then using an index +on the resulting array. Consider the following example: diff --git a/source/reference/method/cursor.toArray.txt b/source/reference/method/cursor.toArray.txt new file mode 100644 index 00000000000..ed2020d908e --- /dev/null +++ b/source/reference/method/cursor.toArray.txt @@ -0,0 +1,28 @@ +================ +cursor.toArray() +================ + +.. default-domain:: mongodb + +.. method:: cursor.toArray() + + The :method:`toArray() ` method iterates a cursor + completely to retrieve the documents and return these documents in + an array. The :method:`toArray() ` method loads + into RAM all documents returned by the cursor and exhausts the + cursor. + + :returns: An array of documents. + +Consider the following example that applies :method:`toArray() +` to the cursor returned from the :method:`find() +` method: + +.. code-block:: javascript + + var docArray = db.products.find().toArray(); + + if (docArray.length > 0) { printjson (docArray[0]); } + +The variable ``docArray`` holds the array of documents returned by +:method:`toArray() `. From 7a5444f58904a6f4bfc979cf6dfb2ea085299f21 Mon Sep 17 00:00:00 2001 From: kay Date: Mon, 7 Jan 2013 15:08:46 -0500 Subject: [PATCH 2/4] DOCS-853 shorten sentences and change variable name --- source/reference/method/cursor.toArray.txt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/source/reference/method/cursor.toArray.txt b/source/reference/method/cursor.toArray.txt index ed2020d908e..201ab7bcee6 100644 --- a/source/reference/method/cursor.toArray.txt +++ b/source/reference/method/cursor.toArray.txt @@ -6,10 +6,9 @@ cursor.toArray() .. method:: cursor.toArray() - The :method:`toArray() ` method iterates a cursor - completely to retrieve the documents and return these documents in - an array. The :method:`toArray() ` method loads - into RAM all documents returned by the cursor and exhausts the + The :method:`toArray() ` method returns an array + that contains all the documents from a cursor. The method loads all + the documents returned by the cursor into RAM and exhausts the cursor. :returns: An array of documents. @@ -20,9 +19,9 @@ Consider the following example that applies :method:`toArray() .. code-block:: javascript - var docArray = db.products.find().toArray(); + var allProductsArray = db.products.find().toArray(); - if (docArray.length > 0) { printjson (docArray[0]); } + if (allProductsArray.length > 0) { printjson (allProductsArray[0]); } -The variable ``docArray`` holds the array of documents returned by +The variable ``allProductsArray`` holds the array of documents returned by :method:`toArray() `. From acad3095e8e380040c656b94e170bcccca4b4f91 Mon Sep 17 00:00:00 2001 From: kay Date: Mon, 7 Jan 2013 15:14:43 -0500 Subject: [PATCH 3/4] DOCS-853 shorten sentences and change variable name --- source/reference/method/cursor.toArray.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/reference/method/cursor.toArray.txt b/source/reference/method/cursor.toArray.txt index 201ab7bcee6..a9b69565d25 100644 --- a/source/reference/method/cursor.toArray.txt +++ b/source/reference/method/cursor.toArray.txt @@ -7,9 +7,9 @@ cursor.toArray() .. method:: cursor.toArray() The :method:`toArray() ` method returns an array - that contains all the documents from a cursor. The method loads all - the documents returned by the cursor into RAM and exhausts the - cursor. + that contains all the documents from a cursor. The method iterates + completely the cursor, loading all the documents into RAM and + exhausting the cursor. :returns: An array of documents. From d5bfde970324d0b334ee6002416cc6e9dec73e17 Mon Sep 17 00:00:00 2001 From: kay Date: Mon, 7 Jan 2013 16:19:50 -0500 Subject: [PATCH 4/4] DOCS-853 use the ~ expression --- source/reference/method/cursor.toArray.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/source/reference/method/cursor.toArray.txt b/source/reference/method/cursor.toArray.txt index a9b69565d25..ba08a45b09c 100644 --- a/source/reference/method/cursor.toArray.txt +++ b/source/reference/method/cursor.toArray.txt @@ -6,16 +6,15 @@ cursor.toArray() .. method:: cursor.toArray() - The :method:`toArray() ` method returns an array - that contains all the documents from a cursor. The method iterates + The :method:`~cursor.toArray()` method returns an array that + contains all the documents from a cursor. The method iterates completely the cursor, loading all the documents into RAM and exhausting the cursor. :returns: An array of documents. -Consider the following example that applies :method:`toArray() -` to the cursor returned from the :method:`find() -` method: +Consider the following example that applies :method:`~cursor.toArray()` +to the cursor returned from the :method:`~db.collection.find()` method: .. code-block:: javascript @@ -24,4 +23,4 @@ Consider the following example that applies :method:`toArray() if (allProductsArray.length > 0) { printjson (allProductsArray[0]); } The variable ``allProductsArray`` holds the array of documents returned by -:method:`toArray() `. +:method:`~cursor.toArray()`.