Skip to content

Commit 5ac11f6

Browse files
author
Chris Cho
authored
DOCSP-10386: address feedback on Count documentation (#104)
1 parent 70088c4 commit 5ac11f6

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

source/code-snippets/usage-examples/count.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,21 @@ async function run() {
1212
await client.connect();
1313

1414
const database = client.db("sample_mflix");
15-
const collection = database.collection("movies");
15+
const movies = database.collection("movies");
1616

1717
// Estimate the total number of documents in the collection
1818
// and print out the count.
19-
var estimate = await collection.estimatedDocumentCount();
20-
console.log(
21-
"Estimated number of documents in the movies collection: " + estimate,
22-
);
19+
const estimate = await movies.estimatedDocumentCount();
20+
console.log(`Estimated number of documents in the movies collection: ${estimate}`);
2321

2422
// Query for movies from Canada.
2523
const query = { countries: "Canada" };
2624

2725
// Find the number of documents that match the specified
2826
// query, (i.e. with "Canada" as a value in the "countries" field)
2927
// and print out the count.
30-
var countCanada = await collection.countDocuments(query);
31-
console.log("Number of movies from Canada: " + countCanada);
28+
const countCanada = await movies.countDocuments(query);
29+
console.log(`Number of movies from Canada: ${countCanada}`);
3230
} finally {
3331
await client.close();
3432
}

source/usage-examples/count.txt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ Count Documents
77
.. note::
88
If you specify a callback method, ``countDocuments()`` and
99
``estimatedDocumentCount()`` return nothing. If you do not specify one,
10-
this method returns a
11-
:mdn:`Promise <Web/JavaScript/Reference/Global_Objects/Promise>` that
12-
resolves to the result object when it completes. For more information on
13-
the result object type, see the
14-
:node-api:`API documentation <Collection.html#~countCallback>`.
10+
this method returns a ``Promise`` that resolves to the result object
11+
when it completes. See our guide on :doc:`Promises and Callbacks
12+
</fundamentals/promises>` for more information, or the
13+
:node-api:`API documentation <Collection.html#~countCallback>` for
14+
information on the result object.
1515

16-
The Node.js driver provides two methods for counting
17-
documents in a collection:
16+
The Node.js driver provides two methods for counting documents in a
17+
collection:
1818

1919
- :node-api:`collection.countDocuments()
2020
<Collection.html#countDocuments>` returns the number of documents in
21-
the collection that match the specified query. If you specify a empty
21+
the collection that match the specified query. If you specify an empty
2222
query document, ``countDocuments()`` returns the total number of
2323
documents in the collection.
2424

@@ -53,3 +53,13 @@ collection with ``Canada`` in the ``countries`` field.
5353

5454
.. literalinclude:: /code-snippets/usage-examples/count.js
5555
:language: javascript
56+
57+
If you run the sample code above, you should see output that resembles the
58+
following:
59+
60+
.. code-block:: none
61+
62+
Estimated number of documents in the movies collection: 23541
63+
Number of movies from Canada: 1349
64+
65+

0 commit comments

Comments
 (0)