Skip to content

Commit a2add6c

Browse files
committed
DOCS-617 removed default write-concern note and added cursor handling
1 parent 8c02da3 commit a2add6c

File tree

5 files changed

+59
-10
lines changed

5 files changed

+59
-10
lines changed

draft/applications/create.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ All insert operations in MongoDB exhibit the following properties:
4141

4242
.. note::
4343

44-
.. include:: /includes/fact-write-concerns.rst
44+
.. .. include:: /includes/fact-write-concerns.rst
4545

4646
.. _crud-create-insert:
4747

draft/applications/delete.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ shell provides this operation, as do corresponding methods in the
2020

2121
.. note::
2222

23-
.. include:: /includes/fact-write-concerns.rst
23+
.. .. include:: /includes/fact-write-concerns.rst
2424

2525
.. _crud-delete-remove:
2626

draft/applications/read.txt

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,46 @@ Consider the following examples that illustrate the use of the
293293
{ _id: 0, 'name.first': 0, birth: 0 }
294294
)
295295

296+
- The following operation finds all documents in the ``bios``
297+
collection and returns the the ``last`` field in the ``name``
298+
subdocument and the first two elements in the ``contribs`` field:
299+
300+
.. code-block:: javascript
301+
302+
db.bios.find(
303+
{ },
304+
{
305+
_id: 0,
306+
'name.last': 1,
307+
contribs: { $slice: 2 }
308+
}
309+
)
310+
311+
Cursor
312+
~~~~~~
313+
314+
:method:`find() <db.collection.find()>` returns a *cursor*; however, in
315+
the :program:`mongo` shell, the cursor is automatically iterated up to
316+
20 times to print the documents referenced by the cursor. To access the
317+
documents, you must explicitly handle the cursor, as in the following
318+
example:
319+
320+
.. code-block:: javascript
321+
322+
var myCursor = db.bios.find( { _id: 1 } );
323+
324+
var myDocument = myCursor.hasNext() ? myCursor.next() : null;
325+
326+
if (myDocument) {
327+
var myName = myDocument.name;
328+
329+
print (tojson(myName));
330+
}
331+
332+
See the :method:`cursor.forEach()`, :method:`cursor.hasNext()`,
333+
:method:`cursor.next()` documentation for more information on cursor
334+
handling.
335+
296336
In addition to the ``<query>`` and the ``<projection>`` arguments, the
297337
:program:`mongo` shell and the :doc:`drivers </applications/drivers>`
298338
provide several cursor methods that you can call on the *cursor*
@@ -437,4 +477,15 @@ because the :method:`findOne() <db.collection.findOne()>` method
437477
returns a document rather than a cursor, you cannot apply the cursor
438478
methods such as :method:`limit() <cursor.limit()>`, :method:`sort()
439479
<cursor.sort()>`, and :method:`skip() <cursor.skip()>` to the result of
440-
the :method:`findOne() <db.collection.findOne()>` method.
480+
the :method:`findOne() <db.collection.findOne()>` method. However, you
481+
can access the document directly, as in the following example:
482+
483+
.. code-block:: javascript
484+
485+
var myDocument = db.bios.findOne();
486+
487+
if (myDocument) {
488+
var myName = myDocument.name;
489+
490+
print (tojson(myName));
491+
}

draft/applications/update.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ methods to perform update operations:
2424

2525
.. note::
2626

27-
- .. include:: /includes/fact-update-field-order.rst
27+
.. include:: /includes/fact-update-field-order.rst
2828

29-
- .. include:: /includes/fact-write-concerns.rst
29+
.. - .. include:: /includes/fact-write-concerns.rst
3030

3131
.. _crud-update-update:
3232

@@ -319,13 +319,11 @@ Consider the following examples of the :method:`save()
319319

320320
- If no ``_id`` field exists or if the ``_id`` field exists but does
321321
not match any document in the collection, the :method:`save()
322-
<db.collection.save()>` method performs an insert. If no ``_id``
323-
field exists, the insert will generate a unique :term:`Object` for
324-
and create an ``_id`` field for the new document.
322+
<db.collection.save()>` method performs an insert.
325323

326324
The following operation adds the ``_id`` field to the document,
327-
assigns to the field a unique ``ObjectId``, and inserts the document
328-
into the ``bios`` collection:
325+
assigns to the field a unique :term:`ObjectId <object-id>`, and
326+
inserts the document into the ``bios`` collection:
329327

330328
.. code-block:: javascript
331329

File renamed without changes.

0 commit comments

Comments
 (0)