Skip to content

Commit 2b99c4f

Browse files
DOCSP-18444 example section (#42)
* updated all example sections
1 parent 84ea79e commit 2b99c4f

File tree

15 files changed

+103
-61
lines changed

15 files changed

+103
-61
lines changed

source/usage-examples/bulkWrite.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ Perform Bulk Operations
77
You can perform bulk write operations on a collection by using the
88
``BulkWrite()`` method.
99

10-
The following example specifies a slice of ``WriteModels`` and an option
11-
to the ``BulkWrite()`` method, which performs the following in order:
12-
13-
- Match a document where the ``title`` is "Record of a Shriveled Datum" and replace it with a new document
14-
- Match a document where the ``title`` is "Dodging Greys" and update that field to "Dodge The Greys"
10+
Example
11+
-------
1512

1613
.. include:: /includes/usage-examples/run-example-tip.rst
1714

15+
The following example performs the following in order on the ``haikus``
16+
collection:
17+
18+
- Matches a document in which the ``title`` is "Record of a Shriveled Datum" and replace it with a new document
19+
- Matches a document in which the ``title`` is "Dodging Greys" and updates that value to "Dodge The Greys"
20+
1821
.. literalinclude:: /includes/usage-examples/code-snippets/bulk.go
1922
:start-after: begin bulk
2023
:end-before: end bulk

source/usage-examples/command.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ Run a Command
77
You can run commands directly on your MongoDB server by using the
88
``RunCommand()`` method.
99

10-
The following example passes a document containing the ``"dbStats"``
11-
command to the ``RunCommand()`` method, which retrieves statistics
12-
about the ``sample_restaurants`` database:
10+
Example
11+
-------
1312

1413
.. include:: /includes/usage-examples/run-example-tip.rst
1514

15+
The following example retrieves statistics about the
16+
``sample_restaurants`` database:
17+
1618
.. literalinclude:: /includes/usage-examples/code-snippets/command.go
1719
:start-after: begin runCommand
1820
:end-before: end runCommand

source/usage-examples/count.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ collection by using the ``EstimatedDocumentCount()`` method and an exact
99
number of documents in a collection by using the ``CountDocuments()``
1010
method.
1111

12-
The following example uses the ``EstimatedDocumentCount()`` method to
13-
count the number of documents in the ``movies`` collection. Then, the
14-
example uses the ``CountDocuments()`` method to count the number of
15-
documents in the ``movies`` collection where the ``countries`` field
16-
contains "China".
12+
Example
13+
-------
1714

1815
.. include:: /includes/usage-examples/run-example-tip.rst
1916

17+
The following example performs the following on the ``movies``
18+
collection:
19+
20+
- Approximates the number of documents in the collection
21+
- Counts the number of documents in which the ``countries`` contains "China"
22+
2023
.. literalinclude:: /includes/usage-examples/code-snippets/count.go
2124
:start-after: begin countDocuments
2225
:end-before: end countDocuments

source/usage-examples/deleteMany.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ Delete Multiple Documents
77
You can delete multiple documents in a collection by using the
88
``DeleteMany()`` method.
99

10-
The following example specifies a query filter to the ``DeleteMany()``
11-
method, which matches documents in the ``movies`` collection where the
12-
``runtime`` field is greater than *800* and deletes all the matching
13-
documents.
10+
Example
11+
-------
1412

1513
.. include:: /includes/usage-examples/run-example-tip.rst
1614

15+
The following example matches documents in the ``movies`` collection
16+
in which the ``runtime`` is greater than 800 minutes, deleting all
17+
documents matched:
18+
1719
.. literalinclude:: /includes/usage-examples/code-snippets/deleteMany.go
1820
:start-after: begin deleteMany
1921
:end-before: end deleteMany

source/usage-examples/deleteOne.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ Delete a Document
77
You can delete a document in a collection by using the ``DeleteOne()``
88
method.
99

10-
The following example specifies a query filter to the ``DeleteOne()``
11-
method, which matches documents in the ``movies`` collection where the
12-
``title`` field is "Twilight", and deletes the first document that
13-
matches.
10+
Example
11+
-------
1412

1513
.. include:: /includes/usage-examples/run-example-tip.rst
1614

15+
The following example matches documents in the ``movies`` collection
16+
in which the ``title`` is "Twilight", deleting the first document
17+
matched:
18+
1719
.. literalinclude:: /includes/usage-examples/code-snippets/deleteOne.go
1820
:start-after: begin deleteOne
1921
:end-before: end deleteOne

source/usage-examples/distinct.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ Retrieve Distinct Values of a Field
77
You can retrieve a list of distinct values for a field across a
88
collection by using the ``Distinct()`` method.
99

10-
The following example specifies a query filter and a field name to the
11-
``Distinct()`` method, which matches documents in the ``movies``
12-
collection where the ``directors`` field contains "Natalie Portman" and
13-
returns distinct values of the ``title`` field from the matched documents.
10+
Example
11+
-------
1412

1513
.. include:: /includes/usage-examples/run-example-tip.rst
1614

15+
The following example performs the following on the ``movies``
16+
collection:
17+
18+
- Matches documents in which the ``directors`` contains "Natalie Portman"
19+
- Returns distinct values of the ``title`` from the matched documents
20+
1721
.. literalinclude:: /includes/usage-examples/code-snippets/distinct.go
1822
:start-after: begin distinct
1923
:end-before: end distinct

source/usage-examples/find.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ Find Multiple Documents
77
You can find multiple documents in a collection by using the ``Find()``
88
method.
99

10-
The following example passes a query filter to the ``Find()`` method,
11-
which matches documents in the ``zips`` collection where the value of the
12-
``pop`` field is less than or equal to *500*:
10+
Example
11+
-------
1312

1413
.. include:: /includes/usage-examples/run-example-tip.rst
1514

15+
The following example matches documents in the ``zips`` collection
16+
in which the ``pop`` is less than or equal to 500 people,
17+
returning all documents matched:
18+
1619
.. literalinclude:: /includes/usage-examples/code-snippets/find.go
1720
:start-after: begin find
1821
:end-before: end find

source/usage-examples/findOne.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ Find a Document
77
You can retrieve a single document from a collection by using the
88
``FindOne()`` method.
99

10-
The following example passes a query filter to the ``FindOne()`` method,
11-
which matches documents in the ``movies`` collection where the value
12-
of the ``title`` field is *The Room*, returning the first document found.
10+
Example
11+
-------
1312

1413
.. include:: /includes/usage-examples/run-example-tip.rst
1514

15+
The following example matches documents in the ``movies`` collection
16+
in which the ``title`` is "The Room", returning the first document
17+
matched:
18+
1619
.. literalinclude:: /includes/usage-examples/code-snippets/findOne.go
1720
:start-after: begin findOne
1821
:end-before: end findOne

source/usage-examples/insertMany.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ Insert Multiple Documents
77
You can insert multiple documents into a collection by using the ``InsertMany()``
88
method.
99

10-
The following example creates a two new document containing a ``title`` and ``text``
11-
field and inserts it into the ``haikus`` collection of the ``insertDB`` database:
10+
Example
11+
-------
12+
13+
.. include:: /includes/usage-examples/run-example-tip.rst
14+
15+
The following example inserts two documents in the ``haikus`` collection:
1216

1317
.. note:: Non-existent Database and Collections
1418

1519
The driver automatically creates the necessary database and/or collection
1620
when you perform a write operation against them if they don't already exist.
1721

18-
19-
.. include:: /includes/usage-examples/run-example-tip.rst
20-
2122
.. literalinclude:: /includes/usage-examples/code-snippets/insertMany.go
2223
:start-after: begin insertMany
2324
:end-before: end insertMany

source/usage-examples/insertOne.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ Insert a Document
77
You can insert a document into a collection by using the ``InsertOne()``
88
method.
99

10-
The following example creates a new document containing a ``title`` and ``text``
11-
field and inserts it into the ``haikus`` collection of the ``insertDB`` database:
10+
Example
11+
-------
12+
13+
.. include:: /includes/usage-examples/run-example-tip.rst
14+
15+
The following example inserts a document in the ``haikus`` collection:
1216

1317
.. note:: Non-existent Database and Collections
1418

1519
The driver automatically creates the necessary database and/or collection
1620
when you perform a write operation against them if they don't already exist.
1721

18-
19-
.. include:: /includes/usage-examples/run-example-tip.rst
20-
2122
.. literalinclude:: /includes/usage-examples/code-snippets/insertOne.go
2223
:start-after: begin insertOne
2324
:end-before: end insertOne

0 commit comments

Comments
 (0)