Skip to content

Commit 6d58fc5

Browse files
committed
DOCS-617 crud draft edits
1 parent 5a2a008 commit 6d58fc5

File tree

6 files changed

+393
-180
lines changed

6 files changed

+393
-180
lines changed

draft/applications/create.txt

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ following syntax:
5151
The :method:`insert() <db.collection.insert()>` method is analogous to
5252
the ``SQL INSERT``.
5353

54-
Consider the following examples that illustrate the usage of the
54+
Consider the following examples that illustrate the use of the
5555
:method:`insert() <db.collection.insert()>` method:
5656

5757
- If the collection does not exist, then the :method:`insert()
@@ -90,8 +90,12 @@ Consider the following examples that illustrate the usage of the
9090

9191
.. code-block:: javascript
9292

93-
> db.csbios.find()
94-
93+
db.csbios.find()
94+
95+
This will return the document from the ``csbios`` collection:
96+
97+
.. code-block:: javascript
98+
9599
{
96100
"_id" : 1,
97101
"name" : { "first" : "John", "last" :"Backus" },
@@ -143,12 +147,17 @@ Consider the following examples that illustrate the usage of the
143147

144148
} )
145149

146-
You can verify the addition of the ``_id`` field to the inserted
147-
document by the querying the ``csbios`` collection:
150+
You can verify the inserted document by the querying the ``csbios``
151+
collection:
148152

149153
.. code-block:: javascript
150154

151-
> db.csbios.find( { name: { first: 'John', last: 'McCarthy' } } )
155+
db.csbios.find( { name: { first: 'John', last: 'McCarthy' } } )
156+
157+
The returned document contains an ``_id`` field with the generated
158+
``ObjectId`` value:
159+
160+
.. code-block:: javascript
152161

153162
{
154163
"_id" : ObjectId("507c294cbcf86cd7994f6c0a"),
@@ -169,7 +178,6 @@ Consider the following examples that illustrate the usage of the
169178
]
170179
}
171180

172-
173181
- If the argument to the :method:`insert() <db.collection.insert()>`
174182
method is an array of documents, then the :method:`insert()
175183
<db.collection.insert()>` method performs a bulk insert into a
@@ -265,7 +273,7 @@ An ``upsert`` has the following syntax:
265273
<update>,
266274
{ upsert: true } )
267275

268-
Consider the following examples that illustrate the usage of the
276+
Consider the following examples that illustrate the use of the
269277
``upsert`` to perform create operations:
270278

271279
- If the ``update`` argument contains only ``field:value`` pairs and no
@@ -352,14 +360,18 @@ Consider the following examples that illustrate the usage of the
352360
{ upsert: true }
353361
)
354362

355-
You can verify that the inserted document contains the ``_id`` and
356-
the ``name`` fields from the ``query`` argument as well as the fields
357-
and values from the ``update`` argument by querying the
358-
``csbios`` collection:
363+
You can verify the inserted document by querying the ``csbios``
364+
collection:
359365

360366
.. code-block:: javascript
361367

362-
> db.csbios.find( { _id: 7 } )
368+
db.csbios.find( { _id: 7 } )
369+
370+
The returned document contains the ``_id`` and the ``name`` fields
371+
from the ``query`` argument as well as the fields and values from the
372+
``update`` argument:
373+
374+
.. code-block:: javascript
363375

364376
{
365377
"_id" : 7,
@@ -416,12 +428,17 @@ Consider the following examples that illustrate the usage of the
416428
{ upsert: true }
417429
)
418430

419-
You can verify the addition of the ``_id`` field to the inserted
420-
document by the querying the ``csbios`` collection:
431+
You can verify the inserted document by the querying the ``csbios``
432+
collection:
421433

422434
.. code-block:: javascript
423435

424-
> db.csbios.find( { name: { first: 'Bjarne', last: 'Stroustrup' } } )
436+
db.csbios.find( { name: { first: 'Bjarne', last: 'Stroustrup' } } )
437+
438+
The returned document contains an ``_id`` field with the generated
439+
``ObjectId`` value:
440+
441+
.. code-block:: javascript
425442

426443
{
427444
"_id" : ObjectId("507c35dd8fada716c89d0013"),
@@ -457,7 +474,7 @@ following syntax:
457474

458475
db.collection.save( <document> )
459476

460-
Consider the following examples that illustrate the usage of the
477+
Consider the following examples that illustrate the use of the
461478
:method:`insert() <db.collection.insert()>` method for create
462479
operations:
463480

@@ -489,7 +506,12 @@ operations:
489506

490507
.. code-block:: javascript
491508

492-
> db.csbios.find( { name: { first: 'Guido', last: 'van Rossum'} } )
509+
db.csbios.find( { name: { first: 'Guido', last: 'van Rossum'} } )
510+
511+
The returned document contains an ``_id`` field with the generated
512+
``ObjectId`` value:
513+
514+
.. code-block:: javascript
493515

494516
{
495517
"_id" : ObjectId("507c387cbcf86cd7994f6c0b"),
@@ -503,7 +525,7 @@ operations:
503525
{ "award" : "NLUUG Award",
504526
"year" : "2003",
505527
"by" : "NLUUG" }
506-
]
528+
]
507529
}
508530

509531
- If the ``document`` contains an ``_id`` field but has a value not
@@ -516,18 +538,16 @@ operations:
516538

517539
.. code-block:: javascript
518540

519-
db.csbios.save(
520-
{
541+
db.csbios.save(
542+
{
521543
_id: 10,
522544
name: { first: 'Yukihiro', aka: 'Matz', last: 'Matsumoto'},
523545
birth: new Date('Apr 14, 1965'),
524546
contribs: [ 'Ruby' ],
525-
awards: [
547+
awards: [
526548
{ award: 'Award for the Advancement of Free Software',
527549
year: '2011',
528550
by: 'Free Software Foundation' }
529551
]
530552
}
531553
)
532-
533-

draft/applications/read.txt

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Read
55
.. default-domain:: mongodb
66

77
Read operation selects documents from a :term:`collection`. MongoDB
8-
provides the following methods to perform create operations:
8+
provides the following methods to perform read operations:
99

1010
- :ref:`find <crud-read-find>`
1111

@@ -30,13 +30,43 @@ syntax:
3030
db.collection.find( <query>, <projection> )
3131

3232
The :method:`find() <db.collection.find()>` method is analogous to the
33-
``SQL SELECT`` with the ``query`` argument analogous to the ``WHERE``
34-
statement and the ``projection`` argument analogous to the selected
35-
fields to return.
33+
``SQL SELECT`` with:
3634

37-
Consider the following examples that illustrate the usage of the
35+
- The ``query`` argument analogous to the ``WHERE`` statement.
36+
37+
- The ``projection`` argument analogous to the selected fields to
38+
return.
39+
40+
Consider the following examples that illustrate the use of the
3841
:method:`find() <db.collection.find()>` method:
3942

43+
The examples refer to a collection named ``csbios`` that contains
44+
documents with the following prototype:
45+
46+
.. code-block:: javascript
47+
48+
{
49+
"_id" : 1,
50+
"name" : { "first" : "John", "last" :"Backus" },
51+
"birth" : ISODate("1924-12-03T05:00:00Z"),
52+
"death" : ISODate("2007-03-17T04:00:00Z"),
53+
"contribs" : [ "Fortran", "ALGOL", "Backus-Naur Form", "FP" ],
54+
"awards" : [
55+
{ "award" : "W.W. McDowellAward",
56+
"year" : "1967",
57+
"by" : "IEEE Computer Society" },
58+
{ "award" : "National Medal of Science",
59+
"year" : "1975",
60+
"by" : "National Science Foundation" },
61+
{ "award" : "Turing Award",
62+
"year" : "1977",
63+
"by" : "ACM" },
64+
{ "award" : "Draper Prize",
65+
"year" : "1993",
66+
"by" : "National Academy of Engineering" }
67+
]
68+
}
69+
4070
.. note::
4171

4272
In the :program:`mongo` shell, you can format the output by adding
@@ -83,9 +113,13 @@ Consider the following examples that illustrate the usage of the
83113

84114
db.csbios.find( { 'name.first': 'Yukihiro', 'name.last': 'Matsumoto' } )
85115

86-
The query matches the document with ``name`` field equal to ``{
87-
first: 'Yukihiro', aka: 'Matz', last: 'Matsumoto'}``.
88-
116+
The query matches the document where the ``name`` field contains a
117+
field ``first`` with the value ``Yukihiro`` and a field ``last``
118+
with the value ``Matsumoto``. For instance, the query would match both:
119+
120+
- ``name: { first: 'Yukihiro', aka: 'Matz', last: 'Matsumoto'}``
121+
- ``name: { last: 'Matsumoto', first: 'Yukihiro'}``.
122+
89123
- The following operation returns all documents in the ``csbios``
90124
collection where the subdocument ``name`` is *exactly* ``{ first:
91125
'Yukihiro', last: 'Matsumoto' }``, including the order of the
@@ -95,10 +129,12 @@ Consider the following examples that illustrate the usage of the
95129

96130
db.csbios.find( { name: { first: 'Yukihiro', last: 'Matsumoto' } } )
97131

98-
The query does *not* match the document with ``name`` field equal
99-
to ``{ first: 'Yukihiro', aka: 'Matz', last: 'Matsumoto'}`` nor
100-
does it match a document with the ``name`` field equal to ``{ last:
101-
'Matsumoto' , first: 'Yukihiro' }``.
132+
The query *only* matches the document where the ``name`` field is
133+
*exactly* ``{ first: 'Yukihiro', last: 'Matsumoto' }``. For
134+
instance, the query would **not** match either:
135+
136+
- ``name: { first: 'Yukihiro', aka: 'Matz', last: 'Matsumoto'}``
137+
- ``name: { last: 'Matsumoto' , first: 'Yukihiro' }``.
102138

103139
- The following operation returns all documents in the ``csbios``
104140
collection where either the field ``first`` in the subdocument
@@ -111,7 +147,6 @@ Consider the following examples that illustrate the usage of the
111147
{ birth: { $lt: new Date('01/01/1945') } }
112148
] } )
113149

114-
115150
- The following operation returns all documents in the ``csbios``
116151
collection where the field ``first`` in the subdocument ``name``
117152
starts with the letter ``K`` **and** the array field ``contribs``
@@ -147,6 +182,19 @@ Consider the following examples that illustrate the usage of the
147182

148183
db.csbios.find( { }, { name: 1, contribs: 1 } )
149184

185+
- The following operation finds all documents in the ``csbios``
186+
collection and returns only the ``name`` field and the ``contribs``
187+
field:
188+
189+
.. code-block:: javascript
190+
191+
db.csbios.find( { }, { name: 1, contribs: 1, _id: 0 } )
192+
193+
.. note::
194+
195+
The ``projection`` argument cannot contain both include and
196+
exclude specifications *except* for the exclusion of the ``_id``.
197+
150198
- The following operation finds the documents in the ``csbios``
151199
collection where the ``contribs`` field contains the element
152200
``OOP`` and returns all fields *except* the ``_id`` field, the
@@ -184,7 +232,6 @@ provides the cursor methods that work with the :method:`find()
184232

185233
db.csbios.find().limit( 5 )
186234

187-
188235
.. _crud-read-findOne:
189236

190237
FindOne
@@ -206,7 +253,7 @@ the :method:`find() <db.collection.find()>` method except the
206253
:method:`findOne() <db.collection.findOne()>` method returns the
207254
single document rather than a cursor.
208255

209-
Consider the following examples that illustrate the usage of the
256+
Consider the following examples that illustrate the use of the
210257
:method:`findOne() <db.collection.findOne()>` method:
211258

212259
- If there is no ``query`` argument, the :method:`findOne()

draft/applications/update.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ the ``SQL UPDATE`` with the ``query`` argument analogous to the
4242
<db.collection.update()>` method provides additional flexibility and
4343
control in use.
4444

45-
Consider the following examples that illustrate the usage of the
45+
Consider the following examples that illustrate the use of the
4646
:method:`update() <db.collection.update()>` method:
4747

4848
- If the ``update`` argument contains only :ref:`update operators

draft/core/documents.txt

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ Documents
44

55
.. default-domain:: mongodb
66

7-
Documents in MongoDB refer to the data structure of the records stored
8-
in :term:`collections <collection>`, the query criteria, the update actions, and
9-
other arguments to MongoDB methods and operators.
7+
The document structure in MongoDB refer to the data structure of the
8+
records stored in :term:`collections <collection>`, the query criteria,
9+
the update actions, and other arguments to MongoDB methods and
10+
operators.
1011

11-
Documents in MongoDB are :term:`BSON` objects with support for the full
12-
range of :term:`BSON types`; however, conceptually, documents may be
13-
viewed as :term:`JSON` objects with the following structure:
12+
The document structure in MongoDB are :term:`BSON` objects with support
13+
for the full range of :term:`BSON types`; however, conceptually,
14+
documents may be viewed as :term:`JSON` objects with the following
15+
structure:
1416

1517
.. code-block:: javascript
1618

@@ -69,7 +71,7 @@ Consider the following examples of MongoDB documents:
6971
{ _id: { $gt: 3 } }
7072

7173
- The following document specifies the query criteria where ``_id``
72-
is equal to ``1`` and the ``name`` field equals the document ``{
74+
is equal to ``1`` **and** the ``name`` field equals the document ``{
7375
first: 'John', last: 'Backus' }``:
7476

7577
.. code-block:: javascript
@@ -112,19 +114,26 @@ Consider the following examples of MongoDB documents:
112114
- The following document specifies the sort order:
113115

114116
.. code-block:: javascript
115-
117+
116118
{ 'name.last': 1 }
117119

118120
When passed as an argument to the :method:`sort() <cursor.sort()>`
119-
method, the document specifies the sort order:
121+
method, the document specifies the sort order of the results:
120122

121123
.. code-block:: javascript
122-
124+
123125
db.csbios.find().sort( { 'name.last': 1 } )
124126

125-
When passed as an argument to the :method:`ensureIndex() <db.collection.ensureIndex()>`
126-
method, the document specifies the index to create:
127+
- The following document specifies the index to create:
128+
129+
.. code-block:: javascript
130+
131+
{ id:1, 'name.last': 1 }
132+
133+
When passed as an argument to the :method:`ensureIndex()
134+
<db.collection.ensureIndex()>` method, the document specifies the
135+
multi-key index to create on the fields ``_id`` and ``name.last``:
127136

128137
.. code-block:: javascript
129138

130-
db.csbios.ensureIndex( { 'name.last': 1 } )
139+
db.csbios.ensureIndex( { id:1, 'name.last': 1 } )

0 commit comments

Comments
 (0)