@@ -6,60 +6,60 @@ const uri =
6
6
"mongodb+srv://<user>:<password>@<cluster-url>?writeConcern=majority" ;
7
7
const client = new MongoClient ( uri ) ;
8
8
9
- async function forEachIteration ( collection ) {
9
+ async function forEachIteration ( myColl ) {
10
10
// start foreach cursor example
11
- const cursor = collection . find ( { } ) ;
11
+ const cursor = myColl . find ( { } ) ;
12
12
await cursor . forEach ( doc => console . log ( doc ) ) ;
13
13
// end foreach cursor example
14
14
console . log ( await cursor . count ( ) ) ;
15
15
}
16
16
17
- async function asyncIteration ( collection ) {
17
+ async function asyncIteration ( myColl ) {
18
18
// start async cursor example
19
- const cursor = collection . find ( { } ) ;
19
+ const cursor = myColl . find ( { } ) ;
20
20
console . log ( "async" ) ;
21
21
for await ( const doc of cursor ) {
22
22
console . log ( doc ) ;
23
23
}
24
24
// end async cursor example
25
25
}
26
26
27
- async function manualIteration ( collection ) {
27
+ async function manualIteration ( myColl ) {
28
28
// start manual cursor example
29
- const cursor = collection . find ( { } ) ;
29
+ const cursor = myColl . find ( { } ) ;
30
30
31
31
while ( await cursor . hasNext ( ) ) {
32
32
console . log ( await cursor . next ( ) ) ;
33
33
}
34
34
// end manual cursor example
35
35
}
36
36
37
- async function streamAPI ( collection ) {
37
+ async function streamAPI ( myColl ) {
38
38
// start stream cursor example
39
- const cursor = collection . find ( { } ) ;
39
+ const cursor = myColl . find ( { } ) ;
40
40
cursor . stream ( ) . on ( "data" , doc => console . log ( doc ) ) ;
41
41
// end stream cursor example
42
42
}
43
43
44
- async function eventAPI ( collection ) {
44
+ async function eventAPI ( myColl ) {
45
45
// start event cursor example
46
- const cursor = collection . find ( { } ) ;
46
+ const cursor = myColl . find ( { } ) ;
47
47
// the "data" event is fired once per document
48
48
cursor . on ( "data" , data => console . log ( data ) ) ;
49
49
// end event cursor example
50
50
}
51
51
52
- async function fetchAll ( collection ) {
52
+ async function fetchAll ( myColl ) {
53
53
// start fetchAll cursor example
54
- const cursor = collection . find ( { } ) ;
54
+ const cursor = myColl . find ( { } ) ;
55
55
const allValues = await cursor . toArray ( ) ;
56
56
// end fetchAll cursor example
57
57
console . log ( allValues . length ) ;
58
58
}
59
59
60
- async function rewind ( collection ) {
60
+ async function rewind ( myColl ) {
61
61
// start rewind cursor example
62
- const cursor = collection . find ( { } ) ;
62
+ const cursor = myColl . find ( { } ) ;
63
63
const firstResult = await cursor . toArray ( ) ;
64
64
console . log ( "First count: " + firstResult . length ) ;
65
65
await cursor . rewind ( ) ;
@@ -68,9 +68,9 @@ async function rewind(collection) {
68
68
// end rewind cursor example
69
69
}
70
70
71
- async function count ( collection ) {
71
+ async function count ( myColl ) {
72
72
// start count cursor example
73
- const cursor = collection . find ( { } ) ;
73
+ const cursor = myColl . find ( { } ) ;
74
74
const count = await cursor . count ( ) ;
75
75
// end count cursor example
76
76
console . log ( count ) ;
0 commit comments