Skip to content

Commit ca3a8fd

Browse files
organizing examples section (#30)
1 parent eb290be commit ca3a8fd

14 files changed

+162
-142
lines changed

source/crud.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Update / Replace
158158
If you want to alter existing documents in a collection, you can use
159159
:doc:`updateOne() </usage-examples/updateOne>`,
160160
:doc:`replaceOne() </usage-examples/replaceOne>`, or
161-
``updateMany()``. These methods
161+
:doc:`updateMany() </usage-examples/updateMany>`. These methods
162162
accept a query document that describes the documents you would like to
163163
change and an :ref:`update document <updateDocument>` that describes
164164
the changes you would like to apply to matched documents.

source/usage-examples.txt

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,46 @@ Usage Examples
44

55
.. default-domain:: mongodb
66

7-
:doc:`bulkWrite </usage-examples/bulkWrite>`
8-
:doc:`countDocuments and estimatedDocumentCount </usage-examples/count>`
9-
:doc:`deleteMany </usage-examples/deleteMany>`
10-
:doc:`insertOne </usage-examples/insertOne>`
11-
:doc:`deleteOne </usage-examples/deleteOne>`
12-
:doc:`find </usage-examples/find>`
13-
:doc:`findOne </usage-examples/findOne>`
14-
:doc:`insertMany </usage-examples/insertMany>`
15-
:doc:`updateOne</usage-examples/updateOne>`
16-
:doc:`updateMany</usage-examples/updateMany>`
17-
:doc:`replaceOne</usage-examples/replaceOne>`
18-
:doc:`distinct</usage-examples/distinct>`
19-
:doc:`command</usage-examples/command>`
7+
- :doc:`Find a Document </usage-examples/findOne>`
8+
9+
- :doc:`Find Multiple Documents </usage-examples/find>`
10+
11+
- :doc:`Insert a Document </usage-examples/insertOne>`
12+
13+
- :doc:`Insert Multiple Documents </usage-examples/insertMany>`
14+
15+
16+
- :doc:`Update a Document</usage-examples/updateOne>`
17+
18+
- :doc:`Replace a Document</usage-examples/replaceOne>`
19+
20+
- :doc:`Update Multiple Documents</usage-examples/updateMany>`
21+
22+
- :doc:`Delete a Document </usage-examples/deleteOne>`
23+
24+
- :doc:`Delete Multiple Documents </usage-examples/deleteMany>`
25+
26+
- :doc:`Count Documents </usage-examples/count>`
27+
28+
- :doc:`Find Distinct Values of a Field </usage-examples/distinct>`
29+
30+
- :doc:`Run a Command </usage-examples/command>`
31+
32+
- :doc:`Perform Bulk Operations </usage-examples/bulkWrite>`
2033

2134
.. toctree::
2235
:caption: Examples
2336

24-
/usage-examples/bulkWrite
25-
/usage-examples/count
26-
/usage-examples/deleteMany
27-
/usage-examples/deleteOne
28-
/usage-examples/insertOne
29-
/usage-examples/find
3037
/usage-examples/findOne
31-
/usage-examples/findOneAndUpdate
38+
/usage-examples/find
39+
/usage-examples/insertOne
3240
/usage-examples/insertMany
3341
/usage-examples/updateOne
34-
/usage-examples/updateMany
3542
/usage-examples/replaceOne
43+
/usage-examples/updateMany
44+
/usage-examples/deleteOne
45+
/usage-examples/deleteMany
46+
/usage-examples/count
3647
/usage-examples/distinct
3748
/usage-examples/command
49+
/usage-examples/bulkWrite

source/usage-examples/command.txt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
=============
2-
Run A Command
2+
Run a Command
33
=============
44

55
.. default-domain:: mongodb
66

77
Overview
88
--------
99

10-
You can run all raw database operations, not including :manual:`CRUD </crud/>`
11-
operations, using the :node-api:`command() </Admin.html#~command>`
12-
method. Typically ``command()`` is used for diagnostic and
13-
administrative tasks, such as fetching server stats or initializing a
14-
replica set.
10+
You can run all raw database operations, not including
11+
:manual:`CRUD </crud/>` operations, using the :node-api:`command()
12+
</Admin.html#~command>` method. Typically ``command()`` is used for
13+
diagnostic and administrative tasks, such as fetching server stats or
14+
initializing a replica set.
1515

1616
.. note::
17-
Use :manual:`collection methods </reference/method/js-collection>` instead of raw db commands whenever possible.
17+
Use :manual:`collection methods </reference/method/js-collection>`
18+
instead of raw db commands whenever possible.
1819

19-
Create an `Object
20-
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object>`_
21-
to specify additional options. Set the ``maxTimeMS`` field of this object to state
22-
the number of milliseconds to wait before aborting the query.
20+
Create an :mdn:`Object
21+
</Web/JavaScript/Reference/Global_Objects/Object>`
22+
to specify additional options. Set the ``maxTimeMS`` field of this
23+
object to state the number of milliseconds to wait before aborting the
24+
query.
2325

24-
The ``command()`` method returns a `Promise
25-
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise>`_
26-
that resolves to an object containing the return object of the operation that was run.
26+
The ``command()`` method returns a :mdn:`Promise
27+
</Web/JavaScript/Reference/Global_Objects/Promise>`
28+
that resolves to an object containing the return object of the operation
29+
that was run.
2730

2831

2932
.. literalinclude:: /code-snippets/usage-examples/command.js
3033
:language: javascript
31-
:linenos:
34+
:linenos:

source/usage-examples/count.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
=============================================
2-
Count the Number of Documents in a Collection
3-
=============================================
1+
===============
2+
Count Documents
3+
===============
44

55
.. default-domain:: mongodb
66

source/usage-examples/deleteMany.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
=====================
2-
Delete Many Documents
3-
=====================
1+
=========================
2+
Delete Multiple Documents
3+
=========================
44

55
.. default-domain:: mongodb
66

source/usage-examples/deleteOne.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
===================
2-
Delete One Document
3-
===================
1+
=================
2+
Delete a Document
3+
=================
44

55
.. default-domain:: mongodb
66

@@ -18,23 +18,24 @@ However, only the first matched document is deleted.
1818
You can define additional query options using the
1919
``options`` object passed as the second parameter of the
2020
``deleteOne`` method. You can also pass a
21-
`callback method <https://mongodb.github.io/node-mongodb-native/3.3/api/Collection.html#~deleteWriteOpCallback>`_
21+
:node-docs:`callback method <api/Collection.html#~deleteWriteOpCallback>`
2222
as an optional third parameter. For detailed reference documentation, see
23-
`collection.deleteOne() <https://mongodb.github.io/node-mongodb-native/3.3/api/Collection.html#deleteOne>`_.
23+
:node-docs:`collection.deleteOne() <api/Collection.html#deleteOne>`.
2424

2525
``deleteOne()`` behaves in two different ways depending on
2626
whether or not a callback method is provided:
2727

2828
- if no callback method is provided, ``deleteOne()`` returns a
29-
`Promise <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise>`_
29+
:mdn:`Promise </Web/JavaScript/Reference/Global_Objects/Promise>`
3030
that resolves to an
31-
`Object <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object>`_
31+
:mdn:`Object </Web/JavaScript/Reference/Global_Objects/Object>`
3232

3333
- if a callback method is provided, ``deleteOne()`` returns
3434
nothing, and instead passes the result object or error object to the
3535
provided callback method
3636

37-
The `result object <http://mongodb.github.io/node-mongodb-native/3.2/api/Collection.html#~deleteWriteOpResult>`_
37+
The :node-docs:`result object
38+
<api/Collection.html#~deleteWriteOpResult>`
3839
contains several keys in the event of a successful execution. You can
3940
use the ``deletedCount`` key to check the number of documents deleted by
4041
the operation. Since ``deleteOne()`` can only delete a single document,
@@ -47,7 +48,8 @@ what caused the operation to fail.
4748

4849
If your application requires the deleted document after deletion,
4950
consider using the
50-
`collection.findOneAndDelete() <https://mongodb.github.io/node-mongodb-native/3.3/api/Collection.html#findOneAndDelete>`_.
51+
:node-docs:`collection.findOneAndDelete()
52+
<api/Collection.html#findOneAndDelete>`.
5153
method, which has a similar interface to ``deleteOne()`` but also
5254
returns the deleted document.
5355

source/usage-examples/distinct.txt

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
1-
==========================================
2-
Distinct Values of a Field in a Collection
3-
==========================================
1+
===============================
2+
Find Distinct Values of a Field
3+
===============================
44

55
.. default-domain:: mongodb
66

7-
You can retrieve a list of distinct values for a field across a collection
8-
by using the `distinct()
9-
<https://mongodb.github.io/node-mongodb-native/3.4/api/Collection.html#distinct>`_
10-
method. Call the ``distinct()`` method on a Collection object with
11-
a document field name parameter as a String to produce a list that contains
12-
one of each of the different values found in the specified document field.
13-
14-
You can specify a document field within an *embedded document* using `dot
15-
notation
16-
<https://docs.mongodb.com/manual/core/document/#embedded-documents>`_. If
17-
you call ``distinct()`` on an document field that contains an array, each
18-
element of the array is treated as a separate value.
19-
20-
You can provide an optional query document to narrow the set of documents that
21-
are searched and an optional Object to specify additional query parameters.
22-
For details on the optional parameters, see the
23-
`distinct() method in the API documentation
24-
<https://mongodb.github.io/node-mongodb-native/3.4/api/Collection.html#distinct>`_.
7+
You can retrieve a list of distinct values for a field across a
8+
collection by using the :node-docs:`distinct()
9+
<api/Collection.html#distinct>` method. Call the ``distinct()`` method
10+
on a Collection object with a document field name parameter as a String
11+
to produce a list that contains one of each of the different values
12+
found in the specified document field.
13+
14+
You can specify a document field within an *embedded document* using
15+
:manual:`dot
16+
notation </core/document/#embedded-documents>`. If
17+
you call ``distinct()`` on an document field that contains an array,
18+
each element of the array is treated as a separate value.
19+
20+
You can provide an optional query document to narrow the set of
21+
documents that are searched and an optional Object to specify additional
22+
query parameters. For details on the optional parameters, see the
23+
:node-docs:`distinct() method in the API documentation
24+
<api/Collection.html#distinct>`.
2525

2626
The ``distinct()`` method returns a
27-
`Promise <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise>`_
28-
that resolves to an
29-
`Array <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array>`_
30-
that contains each of the different values. If none of the documents in the
31-
collection contain the field specified in the method call, it returns an
32-
empty Array.
27+
:mdn:`Promise </Web/JavaScript/Reference/Global_Objects/Promise>` that
28+
resolves to an :mdn:`Array
29+
</Web/JavaScript/Reference/Global_Objects/Array>` that contains each of
30+
the different values. If none of the documents in the collection contain
31+
the field specified in the method call, it returns an empty Array.
3332

3433
If you specify a value for the document field name that is not of type
35-
String such as a Document, Array, Number, or ``null``, the method does not
36-
execute and returns a TypeMismatch error with a message that resembles
37-
the following:
34+
String such as a Document, Array, Number, or ``null``, the method does
35+
not execute and returns a TypeMismatch error with a message that
36+
resembles the following:
3837

3938
::
4039

source/usage-examples/find.txt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Overview
88
--------
99

1010
You can
11-
`query <https://docs.mongodb.com/manual/tutorial/query-documents/#read-operations-query-argument>`_
11+
:doc:`query </crud/query-document>`
1212
for multiple documents in a collection with ``collection.find()``.
1313
The ``find()`` method uses a query document that you provide to match
1414
only the subset of the documents in the collection that match the query.
@@ -17,21 +17,22 @@ MongoDB returns all documents in the collection.
1717

1818

1919
You can also define additional query options such as
20-
`sort <https://docs.mongodb.com/manual/reference/bson-type-comparison-order/index.html>`_
20+
:doc:`sort </crud/read-operations/sort>`
2121
and
22-
`projection <https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/>`_
22+
:doc:`projection </crud/read-operations/project>`
2323
to configure the result set. You should specify these options using the
2424
cursor methods
25-
`sort() <https://mongodb.github.io/node-mongodb-native/3.3/api/Cursor.html#sort>`_
25+
:node-docs:`sort() <api/Cursor.html#sort>`
2626
and
27-
`project() <https://mongodb.github.io/node-mongodb-native/3.3/api/Cursor.html#project>`_.
27+
:node-docs:`project() <api/Cursor.html#project>`.
2828
For detailed reference documentation, see
29-
`collection.find() <https://mongodb.github.io/node-mongodb-native/3.3/api/Collection.html#find>`_.
29+
:node-docs:`collection.find() <api/Collection.html#find>`.
3030

3131
``find()`` returns a
32-
`Cursor <https://mongodb.github.io/node-mongodb-native/3.3/api/Cursor.html>`_
33-
that provides the results of your query. Iterate through the cursor
34-
using cursor methods like ``next()``, ``toArray()``, or ``forEach()`` to
32+
:node-api:`Cursor <api/Cursor.html>`
33+
that provides the results of your query. Iterate through the
34+
:doc:`cursor </crud/read-operations/cursor>` using cursor methods like
35+
``next()``, ``toArray()``, or ``forEach()`` to
3536
fetch and work with the returned documents. If no documents match the
3637
query, ``find()`` returns an empty cursor.
3738

source/usage-examples/findOne.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
=================
2-
Find One Document
3-
=================
1+
===============
2+
Find a Document
3+
===============
44

55
.. default-domain:: mongodb
66

@@ -49,7 +49,7 @@ collection. It uses the following:
4949
returned documents and explicitly includes only the ``title`` and
5050
``imdb`` object (and its embedded fields).
5151

52-
.. literalinclude:: /code-snippets/usage-examples/find.js
52+
.. literalinclude:: /code-snippets/usage-examples/findOne.js
5353
:language: javascript
5454
:emphasize-lines: 26
5555
:linenos:

source/usage-examples/insertMany.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
=====================
2-
Create Many Documents
3-
=====================
1+
=========================
2+
Insert Multiple Documents
3+
=========================
44

55
.. default-domain:: mongodb
66

7-
You can create multiple documents using the `insertMany()
7+
You can insert multiple documents using the `insertMany()
88
<https://mongodb.github.io/node-mongodb-native/3.3/api/Collection.html#insertMany>`_
99
method. The ``insertMany()`` takes an array of documents to insert into
1010
the specified collection.

0 commit comments

Comments
 (0)