Skip to content

Commit 1ea6fc7

Browse files
authored
remove count (#587)
1 parent 69c2e08 commit 1ea6fc7

File tree

7 files changed

+13
-28
lines changed

7 files changed

+13
-28
lines changed

source/code-snippets/crud/cursor.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function forEachIteration(myColl) {
1111
const cursor = myColl.find({});
1212
await cursor.forEach(doc => console.log(doc));
1313
// end foreach cursor example
14-
console.log(await cursor.count());
14+
console.log(await myColl.countDocuments());
1515
}
1616

1717
async function asyncIteration(myColl) {
@@ -68,12 +68,8 @@ async function rewind(myColl) {
6868
// end rewind cursor example
6969
}
7070

71-
async function count(myColl) {
72-
// start count cursor example
71+
async function close(myColl) {
7372
const cursor = myColl.find({});
74-
const count = await cursor.count();
75-
// end count cursor example
76-
console.log(count);
7773

7874
// start close cursor example
7975
await cursor.close();

source/code-snippets/crud/startrek.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function word(movies) {
2020
// end word text example
2121

2222
// print a message if no documents were found
23-
if ((await cursor.count()) === 0) {
23+
if ((await movies.countDocuments(query)) === 0) {
2424
console.log("No documents found!");
2525
}
2626
await cursor.forEach(console.dir);
@@ -41,7 +41,7 @@ async function phrase(movies) {
4141
// end phrase text example
4242

4343
// print a message if no documents were found
44-
if ((await cursor.count()) == 0) {
44+
if ((await movies.countDocuments(query)) === 0) {
4545
console.log("No documents found!");
4646
}
4747
await cursor.forEach(console.dir);
@@ -62,7 +62,7 @@ async function negation(movies) {
6262
// end negation text example
6363

6464
// print a message if no documents were found
65-
if ((await cursor.count()) == 0) {
65+
if ((await movies.countDocuments(query)) === 0) {
6666
console.log("No documents found!");
6767
}
6868
await cursor.forEach(console.dir);
@@ -89,7 +89,7 @@ async function relevance(movies) {
8989
// end relevance text example
9090

9191
// print a message if no documents were found
92-
if ((await cursor.count()) === 0) {
92+
if ((await movies.countDocuments(query)) === 0) {
9393
console.log("No documents found!");
9494
}
9595
await cursor.forEach(console.dir);

source/code-snippets/crud/theaters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function proximity(theaters) {
2121
// end proximity geo example
2222

2323
// print a message if no documents were found
24-
if ((await cursor.count()) == 0) {
24+
if ((await theaters.countDocuments(query)) === 0) {
2525
console.log("No documents found!");
2626
}
2727
await cursor.forEach(console.dir);
@@ -52,7 +52,7 @@ async function range(theaters) {
5252
// end range geo example
5353

5454
// print a message if no documents were found
55-
if ((await cursor.count()) === 0) {
55+
if ((await theaters.countDocuments(query)) === 0) {
5656
console.log("No documents found!");
5757
}
5858
await cursor.forEach(console.dir);
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Execute a find command
22
await collection
33
.find({ $where: "sleep(100) || true" })
4-
.maxTimeMS(50)
5-
.count((err, count) => {});
4+
.maxTimeMS(50);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async function run() {
2323
const cursor = movies.find(query, options);
2424

2525
// print a message if no documents were found
26-
if ((await cursor.count()) === 0) {
26+
if ((await movies.countDocuments(query)) === 0) {
2727
console.log("No documents found!");
2828
}
2929

source/code-snippets/usage-examples/find.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ async function run() {
2424
const database = client.db("sample_mflix");
2525
const movies = database.collection<Movie>("movies");
2626

27+
const query = { runtime: { $lt: 15 } };
2728
const cursor = movies.find<Movie>(
28-
{ runtime: { $lt: 15 } },
29+
query,
2930
{
3031
sort: { title: 1 },
3132
projection: { _id: 0, title: 1, imdb: 1 },
3233
}
3334
);
3435

35-
if ((await cursor.count()) === 0) {
36+
if ((await movies.countDocuments(query)) === 0) {
3637
console.warn("No documents found!");
3738
}
3839

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,6 @@ As Readable Streams, cursors also support the Event API's
148148
Cursor Utility Methods
149149
----------------------
150150

151-
Count
152-
~~~~~
153-
154-
For an estimated count of the number of documents referenced by the
155-
cursor, use `count() <{+api+}/classes/FindCursor.html#count>`__:
156-
157-
.. literalinclude:: /code-snippets/crud/cursor.js
158-
:language: javascript
159-
:start-after: start count cursor example
160-
:end-before: end count cursor example
161-
162151
Rewind
163152
~~~~~~
164153

0 commit comments

Comments
 (0)