Skip to content

Commit 94547eb

Browse files
DOCSP-16397 headings and sidebar toc (#177)
* added sidebar TOC
1 parent 3c05c11 commit 94547eb

File tree

9 files changed

+100
-11
lines changed

9 files changed

+100
-11
lines changed

source/fundamentals/crud/compound-operations.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Compound Operations
1010
:depth: 1
1111
:class: singlecol
1212

13+
Overview
14+
--------
15+
1316
Most database requests only need to read data out of a database or
1417
write data into a database. However, client applications sometimes need
1518
to read and write data in a single interaction with the database.
@@ -35,7 +38,7 @@ multiple potential error states. This increases the complexity of your
3538
code and can make your client application brittle and difficult to test.
3639

3740
Built-in Methods
38-
~~~~~~~~~~~~~~~~
41+
----------------
3942

4043
There are three major compound operations:
4144

source/fundamentals/crud/read-operations/cursor.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Access Data From a Cursor
1010
:depth: 2
1111
:class: singlecol
1212

13+
Overview
14+
--------
15+
1316
Read operations that return multiple documents do not immediately return
1417
all values matching the query. Because a query can potentially match
1518
very large sets of documents, these operations rely upon an

source/fundamentals/crud/read-operations/limit.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ Limit the Number of Returned Results
44

55
.. default-domain:: mongodb
66

7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
Overview
14+
--------
15+
716
Use ``limit`` to cap the number of documents that can be returned from a
817
read operation. ``limit`` functions as a cap on the maximum number of
918
documents that the operation can return, but the operation can return
@@ -13,6 +22,9 @@ to reach the limit. If ``limit`` is used with the
1322
first and the limit only applies to the documents left over after
1423
the skip.
1524

25+
Sample Documents
26+
~~~~~~~~~~~~~~~~
27+
1628
Follow the instructions in the examples below to insert data into
1729
a collection and return only certain results from a query using a sort,
1830
a skip, and a limit. Consider the following collection of documents that
@@ -29,6 +41,9 @@ describe books:
2941
{ "_id": 6, "name": "A Dance With Dragons", "author": "Tolkein", "length": 1104 },
3042
]
3143

44+
Limit
45+
-----
46+
3247
The following example queries the collection to return the top three
3348
longest books. It matches all the documents with the query, applies
3449
a ``sort`` on the ``length`` field to return books with longer lengths before
@@ -78,6 +93,9 @@ For more information on the ``options`` settings for the ``find()``
7893
method, see the
7994
:node-api:`API documentation on find() <Collection.html#find>`.
8095

96+
Skip
97+
----
98+
8199
To see the next three books in the results, append the ``skip()`` method,
82100
passing the number of documents to bypass as shown below:
83101

source/fundamentals/crud/read-operations/project.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ Specify Which Fields to Return
44

55
.. default-domain:: mongodb
66

7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
Overview
14+
--------
15+
716
Use a projection to control which fields appear in the documents
817
returned by read operations. Many requests only require certain fields,
918
so projections can help you limit unnecessary network bandwidth usage.
@@ -19,6 +28,9 @@ These two methods of projection are mutually exclusive: if you
1928
explicitly include fields, you cannot explicitly exclude fields, and
2029
vice versa.
2130

31+
Sample Documents
32+
~~~~~~~~~~~~~~~~
33+
2234
Consider the following collection containing documents that describe
2335
varieties of fruit:
2436

@@ -31,6 +43,9 @@ varieties of fruit:
3143
{ "_id": 4, "name": "avocados", "qty": 3, "rating": 5 },
3244
]
3345

46+
Single Field
47+
------------
48+
3449
In the following query, pass the projection to only return the ``name``
3550
field of each document:
3651

@@ -93,6 +108,9 @@ the following results:
93108
{ "name": "oranges" }
94109
{ "name": "avocados" }
95110

111+
Multiple Fields
112+
---------------
113+
96114
You can also specify multiple fields to include in your projection. Note: the
97115
order in which you specify the fields in the projection does not alter the
98116
order in which they are returned.

source/fundamentals/crud/read-operations/skip.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Skip Returned Results
44

55
.. default-domain:: mongodb
66

7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
Overview
14+
--------
715

816
Use ``skip`` to omit documents from the beginning of the list of
917
returned documents for a read operation. You can combine ``skip`` with
@@ -17,6 +25,9 @@ arbitrary documents.
1725
If the value of ``skip`` exceeds the number of matched documents for
1826
a query, that query returns no documents.
1927

28+
Sample Documents
29+
~~~~~~~~~~~~~~~~
30+
2031
Follow the instructions in the examples below to insert data into
2132
a collection and perform a sort and skip on the results of a query.
2233
Consider a collection containing documents that describe varieties of
@@ -31,6 +42,9 @@ fruit:
3142
{ "_id": 4, "name": "avocados", "qty": 3, "rating": 5 },
3243
]
3344

45+
Example
46+
-------
47+
3448
In the following example, we query the collection with a filter that
3549
matches all the documents and pass options that specifies ``sort`` and
3650
``skip`` commands as query options. The sort option specifies that fruit

source/fundamentals/crud/read-operations/sort.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ Sort Results
44

55
.. default-domain:: mongodb
66

7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
Overview
14+
--------
15+
716
Use ``sort`` to change the order in which read operations return
817
documents. ``Sort`` tells MongoDB to order returned documents by the
918
values of one or more fields in a certain direction. To sort returned
@@ -12,6 +21,9 @@ documents by a field in ascending (lowest first) order, use a value of
1221
If you do not specify a sort, MongoDB does not guarantee the order of
1322
query results.
1423

24+
Sample Documents
25+
~~~~~~~~~~~~~~~~
26+
1527
Follow the instructions in the examples below to insert data into
1628
a collection and perform a sort on the results of a query.
1729
Consider a collection containing documents that describe books. To
@@ -28,6 +40,9 @@ insert this data into a collection, run the following operation:
2840
{ "_id": 6, "name": "A Dance with Dragons", "author": "Martin", "length": 1104 },
2941
]);
3042

43+
Example
44+
-------
45+
3146
Pass the following sort document to a read operation to ensure that the
3247
operation returns books with longer lengths before books with shorter
3348
lengths:

source/fundamentals/crud/write-operations/embedded-arrays.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ Update Arrays in a Document
77
.. contents:: On this page
88
:local:
99
:backlinks: none
10-
:depth: 1
10+
:depth: 2
1111
:class: singlecol
1212

13+
Overview
14+
--------
15+
1316
If you need to modify an array embedded within a document, you can use an
1417
array update operator in your update method call. In this guide, we
1518
explain and show examples on usage of these operators including:
@@ -22,8 +25,8 @@ See the MongoDB server guide on
2225
:manual:`Update Operators </reference/operator/update-array/#update-operators>`
2326
for a complete list.
2427

25-
Examples
26-
~~~~~~~~
28+
Sample Documents
29+
~~~~~~~~~~~~~~~~
2730

2831
The following examples use a database called ``test`` and collection
2932
called ``pizza`` which contains documents that describe customers and
@@ -89,7 +92,7 @@ the following sample document to follow the example queries:
8992
.. _first-match-operator:
9093

9194
Match the First Array Element
92-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95+
-----------------------------
9396

9497
To perform the update on only the first array element of each document
9598
that matches your query document in your update operation, use the ``$``
@@ -144,7 +147,7 @@ in our update, we encounter the following error:
144147
.. _all-match-operator:
145148

146149
Match All Array Elements
147-
~~~~~~~~~~~~~~~~~~~~~~~~
150+
------------------------
148151

149152
To perform the update on all of the array elements of each document that
150153
matches your query document in your update operation, use the all
@@ -184,7 +187,7 @@ resemble the following:
184187
.. _filtered-positional-operator:
185188

186189
Filtered Positional Operator
187-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190+
----------------------------
188191

189192
In the previous sections, we used the ``$`` operator to match the first
190193
array element and the ``$[]`` operator to match all array elements. In this

source/fundamentals/crud/write-operations/insert.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ generates a unique ``_id`` field for documents unless specified.
2727
The following examples use a collection called ``pizzaCollection``,
2828
which contains documents with the name and shape of a pizza.
2929

30-
Insert a Document Example
31-
~~~~~~~~~~~~~~~~~~~~~~~~~
30+
Insert a Document
31+
~~~~~~~~~~~~~~~~~
3232

3333
You can specify a document in a JSON object as follows:
3434

@@ -56,8 +56,8 @@ You can print the number of documents inserted by accessing the
5656
For a runnable example, see the :doc:`insertOne() </usage-examples/insertOne>`
5757
usage example.
5858

59-
Insert Multiple Documents Example
60-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59+
Insert Multiple Documents
60+
~~~~~~~~~~~~~~~~~~~~~~~~~
6161

6262
You can specify multiple documents in an array of JSON objects as follows:
6363

source/fundamentals/crud/write-operations/upsert.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ Insert or Update in a Single Operation
44

55
.. default-domain:: mongodb
66

7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
Overview
14+
--------
15+
716
If your application stores and modifies data in MongoDB, you probably use
817
insert and update operations. In certain workflows, you may need to choose
918
between an insert and update depending on whether the document exists.
@@ -18,6 +27,9 @@ If the query filter passed to these methods does not find any matches and
1827
you set the ``upsert`` option to ``true``, MongoDB inserts the update
1928
document. Let's go through an example.
2029

30+
Performing an Update
31+
--------------------
32+
2133
Suppose your application tracks the current location of food trucks,
2234
storing the nearest address data in a MongoDB collection that resembles the
2335
following:
@@ -47,6 +59,9 @@ If a food truck named "Deli Llama" exists, the method call above updates
4759
the document in the collection. However, if there are no food trucks named
4860
"Deli Llama" in your collection, no changes are made.
4961

62+
Performing an Upsert
63+
--------------------
64+
5065
Consider the case in which you want to add information about the food
5166
truck even if it does not currently exist in your collection. Rather than
5267
first querying whether it exists to determine whether we need to insert or

0 commit comments

Comments
 (0)