Skip to content

Commit 44e329e

Browse files
committed
DOCS-617 edits to CR of CRUD
1 parent 408c1f7 commit 44e329e

File tree

2 files changed

+56
-75
lines changed

2 files changed

+56
-75
lines changed

draft/applications/create.txt

Lines changed: 49 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Create
66

77
Of the four basic database operations (i.e. CRUD), *create* operations
88
are those that add new records or :term:`documents <document>` to a
9-
:term:`collection` in MongoDB. For more information about document
10-
creation and other write operations see :ref:`/core/write-operations`,
11-
for documentation of other basic database operations see the
12-
:doc:`/crud` page.
9+
:term:`collection` in MongoDB. For general information related to
10+
document creation and other write operations, see
11+
:ref:`/core/write-operations`; for documentation of the other CRUD
12+
operations, see the :doc:`/crud` page.
1313

1414
Overview
1515
--------
@@ -23,15 +23,15 @@ following basic operations.
2323

2424
- :ref:`save <crud-create-save>`
2525

26-
All insert operations in MongoDB the following properties:
26+
All insert operations in MongoDB exhibit the following properties:
2727

28-
- If you attempt to insert a document without :term:`_id` field, the
29-
client library *or* the :program:`mongod` instance will add an
30-
``_id`` an populate the field with a unique :term:`ObjectId
28+
- If you attempt to insert a document without the :term:`_id` field,
29+
the client library *or* the :program:`mongod` instance will add an
30+
``_id`` field and populate the field with a unique :term:`ObjectId
3131
<objectid>`.
3232

3333
- If you specify an ``_id`` field, the ``_id`` field must be unique
34-
within the collection, otherwise the :program:`mongod` will return a
34+
within the collection; otherwise the :program:`mongod` will return a
3535
duplicate key exception.
3636

3737
- .. include:: /includes/fact-document-max-size.rst
@@ -55,17 +55,19 @@ the following syntax:
5555

5656
db.collection.insert( <document> )
5757

58-
The :method:`insert() <db.collection.insert()>` method is analogous to
59-
the ``INSERT`` statement in SQL. To illustrate the behavior of
60-
:method:`insert() <db.collection.insert()>`, consider the following
61-
examples:
58+
.. admonition:: Corresponding Operation in SQL
59+
60+
The :method:`insert() <db.collection.insert()>` method is analogous
61+
to the ``INSERT`` statement.
62+
63+
Consider the following examples that illustrate the behavior of
64+
:method:`insert() <db.collection.insert()>`:
6265

6366
- If the collection does not exist, then the :method:`insert()
6467
<db.collection.insert()>` method creates the collection during the
65-
first insert.
66-
67-
If the collection ``csbios`` does not exist, then following
68-
operation will create this collection:
68+
first insert. Specifically in the example, if the collection
69+
``csbios`` does not exist, then the insert operation will create this
70+
collection:
6971

7072
.. code-block:: javascript
7173

@@ -129,10 +131,6 @@ examples:
129131
:method:`insert() <db.collection.insert()>` method adds the ``_id``
130132
field to the document and generates a unique ``ObjectId`` for the value.
131133

132-
The following operation adds the ``_id`` field to the document,
133-
assigns to the field a unique ``ObjectId``, and inserts the document
134-
into the ``csbios`` collection:
135-
136134
.. code-block:: javascript
137135

138136
db.csbios.insert( {
@@ -186,7 +184,7 @@ examples:
186184
}
187185

188186
- If you pass an array of documents to the :method:`insert()
189-
<db.collection.insert()>` method the :method:`insert()
187+
<db.collection.insert()>` method, the :method:`insert()
190188
<db.collection.insert()>` performs a bulk insert into a collection.
191189

192190
The following operation inserts three documents into the
@@ -268,15 +266,20 @@ examples:
268266
Update with Upsert
269267
------------------
270268

271-
Typically update operations :doc:`update </applications/update>`
272-
existing documents, but in MongoDB, the :method:`update()
273-
<db.collection.update()>` operation has an ``upsert`` option. Upserts
274-
are a hybrid operation, that use the query argument to the update
275-
operation and:
269+
An update with upsert or an *upsert* eliminates the need to perform a
270+
separate database call to check for the existence of a record before
271+
performing either an update or an insert operation. Typically update
272+
operations :doc:`update </applications/update>` existing documents, but
273+
in MongoDB, the :method:`update() <db.collection.update()>` operation
274+
can accept an ``upsert`` option as an argument. Upserts are a hybrid
275+
operation that use the ``query`` argument to determine the write
276+
operation:
276277

277-
- update the matching document if the query returns a result.
278+
- If the query returns a result, the upsert updates the matching
279+
document.
278280

279-
- inserts a single document if no document matches the query.
281+
- If the query matches no document in the collection, the upsert
282+
inserts a single document.
280283

281284
Consider the following syntax for an upsert operation:
282285

@@ -286,7 +289,7 @@ Consider the following syntax for an upsert operation:
286289
<update>,
287290
{ upsert: true } )
288291

289-
Consider the following examples that illustrate the use of the
292+
The following examples illustrate the use of the
290293
upsert to perform create operations:
291294

292295
- If the ``<update>`` argument contains only field and value
@@ -472,12 +475,16 @@ upsert to perform create operations:
472475
Save
473476
----
474477

475-
The :method:`save() <db.collection.save()>` method inserts a document
476-
into a collection if the document does not contain the ``_id`` field or
477-
contains an ``_id`` field with a value not in the collection. If the
478-
document does not contain the ``_id`` field, the :method:`save()
479-
<db.collection.save()>` method adds the ``_id`` field to the document
480-
and assigns a unique ``ObjectId`` as its value.
478+
The :method:`save() <db.collection.save()>` method is a specialized
479+
upsert that use the ``_id`` field in document argument to determine
480+
whether to perform an insert or an update:
481+
482+
- If the document does not contain the ``_id`` field or contains an
483+
``_id`` field with a value not in the collection, the :method:`save()
484+
<db.collection.save()>` method performs an insert of the document.
485+
486+
- Otherwise, the :method:`save() <db.collection.save()>` method
487+
performs an update.
481488

482489
The :method:`save() <db.collection.save()>` method has the
483490
following syntax:
@@ -487,12 +494,12 @@ following syntax:
487494
db.collection.save( <document> )
488495

489496
Consider the following examples that illustrate the use of the
490-
:method:`insert() <db.collection.insert()>` method for create
491-
operations:
497+
:method:`save() <db.collection.save()>` method to perform inserts:
492498

493499
- If the ``document`` does not contain the ``_id`` field, the
494-
:method:`save() <db.collection.save()>` method adds the ``_id`` field
495-
to the document and performs an insert.
500+
:method:`save() <db.collection.save()>` method performs an insert.
501+
Refer to the :ref:`insert <crud-create-insert>` section for details
502+
of the insert operation of a document without an ``_id`` field.
496503

497504
The following operation performs an insert into the ``csbios``
498505
collection since the document does not contain the ``_id`` field:
@@ -513,36 +520,10 @@ operations:
513520
]
514521
} )
515522

516-
You can verify the addition of the ``_id`` field during the operation
517-
by querying the ``csbios`` collection:
518-
519-
.. code-block:: javascript
520-
521-
db.csbios.find( { name: { first: 'Guido', last: 'van Rossum'} } )
522-
523-
The returned document contains an ``_id`` field with the generated
524-
``ObjectId`` value:
525-
526-
.. code-block:: javascript
527-
528-
{
529-
"_id" : ObjectId("507c387cbcf86cd7994f6c0b"),
530-
"name" : { "first" : "Guido", "last" : "van Rossum" },
531-
"birth" : ISODate("1956-01-31T05:00:00Z"),
532-
"contribs" : [ "Python" ],
533-
"awards" :[
534-
{ "award" : "Award for the Advancement of Free Software",
535-
"year" : "2001",
536-
"by" : "Free Software Foundation" },
537-
{ "award" : "NLUUG Award",
538-
"year" : "2003",
539-
"by" : "NLUUG" }
540-
]
541-
}
542-
543523
- If the ``document`` contains an ``_id`` field but has a value not
544524
found in the collection, the :method:`save() <db.collection.save()>`
545-
method performs an insert.
525+
method performs an insert. Refer to the :ref:`insert
526+
<crud-create-insert>` section for details of the insert operation.
546527

547528
The following operation performs an insert into the ``csbios``
548529
collection since the document contains an ``_id`` field whose value

draft/applications/read.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Read
66

77
Of the four basic database operations (i.e. CRUD), read operation are
88
those that retrieve records or or :term:`documents <document>` from a
9-
:term:`collection` in MongoDB. For more information about document
10-
retrieval and other read operations see :ref:`/core/read-operations`,
11-
for documentation of other basic database operations see the
12-
:doc:`/crud` page.
9+
:term:`collection` in MongoDB. For general information about read
10+
operations and the factors that affect their performanace, see
11+
:ref:`/core/read-operations`; for documentation of the other CRUD
12+
operations, see the :doc:`/crud` page.
1313

1414
Overview
1515
--------
@@ -31,15 +31,15 @@ method to select documents from a collection. The :method:`find()
3131
<db.collection.find()>` method returns a cursor that contains a number
3232
of documents. Most :doc:`drivers </applications/drivers>` provide
3333
application developers with a native iterable interface for handling
34-
cursors and accessing documents
34+
cursors and accessing documents.
3535
The :method:`find() <db.collection.find()>` method has the following
3636
syntax:
3737

3838
.. code-block:: javascript
3939

4040
db.collection.find( <query>, <projection> )
4141

42-
.. optional:: Corresponding operations in SQL.
42+
.. admonition:: Corresponding Operation in SQL
4343

4444
The :method:`find() <db.collection.find()>` method is analogous to
4545
the ``SELECT`` statement, while:
@@ -244,7 +244,7 @@ operation. These methods are:
244244

245245
db.csbios.find().sort( { name: 1 } )
246246

247-
:method:`sort() <cursor.sort()>` corresponds to the is ``ORDER BY``
247+
:method:`sort() <cursor.sort()>` corresponds to the ``ORDER BY``
248248
statement in SQL.
249249

250250
- The :method:`limit() <cursor.limit()>` method limits the number of

0 commit comments

Comments
 (0)