Skip to content

Commit d2d8f67

Browse files
authored
consistent await in quick reference (#423)
* remove unnecessary awaits * remove unused import
1 parent b522fa4 commit d2d8f67

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

source/code-snippets/quick-reference.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,37 @@ const uri =
88
const client = new MongoClient(uri);
99

1010
async function query(coll) {
11-
await console.log("findOne");
11+
console.log("findOne");
1212
const result = await coll.findOne({ title: 'Hamlet' });
13-
await console.dir(result);
13+
console.dir(result);
1414
}
1515

1616
async function queryMany(coll) {
17-
await console.log("find");
18-
const cursor = await coll.find({ year: 2005 });
17+
console.log("find");
18+
const cursor = coll.find({ year: 2005 });
1919
await cursor.forEach(console.dir);
2020
}
2121

2222
async function insertOne(coll) {
2323
const result = await coll.insertOne({
2424
title: 'Jackie Robinson',
2525
});
26-
await console.dir(result);
26+
console.dir(result);
2727
}
2828
async function insertMany(coll) {
2929
const result = await coll.insertMany([
3030
{ title: 'Dangal', rating: 'Not Rated' },
3131
{ title: 'The Boss Baby', rating: 'PG' }
3232
]);
33-
await console.dir(result);
33+
console.dir(result);
3434
}
3535

3636
async function updateOne(coll) {
3737
const result = await coll.updateOne(
3838
{ title: 'Amadeus' },
3939
{ $set: { 'imdb.rating': 9.5 } }
4040
);
41-
await console.dir(result);
41+
console.dir(result);
4242
}
4343

4444
async function updateMany(coll) {
@@ -47,18 +47,18 @@ async function updateMany(coll) {
4747
{ $inc: { 'imdb.votes': 100 } }
4848
);
4949

50-
await console.dir(result);
50+
console.dir(result);
5151
}
5252

5353
async function updateArrayElement(coll) {
5454
const result = await coll.updateOne(
5555
{ title: 'Cosmos' },
5656
{ $push: { genres: 'Educational' } }
5757
);
58-
await console.dir(result);
58+
console.dir(result);
5959

6060
const findResult = await coll.findOne({title: 'Cosmos'});
61-
await console.dir(findResult);
61+
console.dir(findResult);
6262
}
6363

6464
async function replaceDocument(coll) {
@@ -67,20 +67,20 @@ async function replaceDocument(coll) {
6767
{ name: 'Lord of the Wings', zipcode: 10001 },
6868
{ upsert: true}
6969
);
70-
await console.dir(result);
70+
console.dir(result);
7171

7272
const findResult = await coll.findOne({name: 'Lord of the Wings'});
73-
await console.dir(findResult);
73+
console.dir(findResult);
7474
}
7575

7676
async function deleteOne(coll) {
7777
const result = await coll.deleteOne({ title: 'Congo' });
78-
await console.dir(result);
78+
console.dir(result);
7979
}
8080

8181
async function deleteMany(coll) {
8282
const result = await coll.deleteMany({ title: { $regex: /^Shark.*/ } });
83-
await console.dir(result);
83+
console.dir(result);
8484
}
8585

8686
async function bulkWriteExample(coll) {
@@ -99,7 +99,7 @@ async function bulkWriteExample(coll) {
9999
}
100100
}
101101
]);
102-
await console.dir(result);
102+
console.dir(result);
103103
}
104104

105105
async function watchStart(coll) {
@@ -119,21 +119,21 @@ async function accessCursorArray(coll) {
119119

120120
async function createIndex(coll) {
121121
const result = await coll.createIndex({'title':1 , 'year':-1});
122-
await console.dir(result);
122+
console.dir(result);
123123
}
124124

125125
async function countExample(coll) {
126126
const result = await coll.countDocuments({year: 2000});
127-
await console.dir(result);
127+
console.dir(result);
128128
}
129129

130130
async function skipExample(coll) {
131-
const cursor = await coll.find({title: {$regex: /^Rocky/ }}, { skip: 2 });
132-
await console.dir(await cursor.toArray());
131+
const cursor = coll.find({title: {$regex: /^Rocky/ }}, { skip: 2 });
132+
console.dir(await cursor.toArray());
133133
}
134134

135135
async function sortExample(coll) {
136-
const cursor = await coll.find().limit(50).sort({ year: 1});
136+
const cursor = coll.find().limit(50).sort({ year: 1});
137137
await cursor.forEach(console.dir);
138138
}
139139

@@ -143,13 +143,13 @@ async function projectExample(coll) {
143143
}
144144

145145
async function searchText(coll) {
146-
const result = await coll.find({$text: { $search: 'zissou' }}).limit(30).project({title: 1});
146+
const result = coll.find({$text: { $search: 'zissou' }}).limit(30).project({title: 1});
147147
await result.forEach(console.dir);
148148
}
149149

150150
async function distinct(coll) {
151151
const result = await coll.distinct('year');
152-
await console.log(result);
152+
console.log(result);
153153
}
154154

155155
async function run() {

source/quick-reference.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ their related reference and API documentation.
2828
.. input::
2929
:language: js
3030

31-
coll.findOne({ title: 'Hamlet' });
31+
await coll.findOne({ title: 'Hamlet' });
3232

3333
.. output::
3434
:language: js
35-
:visible: false
35+
:visible: false
3636

3737
{ title: 'Hamlet', type: 'movie', ... }
3838

@@ -69,7 +69,7 @@ their related reference and API documentation.
6969
- .. code-block:: javascript
7070
:copyable: true
7171

72-
coll.insert({ title: 'Jackie Robinson' });
72+
await coll.insert({ title: 'Jackie Robinson' });
7373

7474
* - | **Insert Multiple Documents**
7575
|
@@ -80,7 +80,7 @@ their related reference and API documentation.
8080
- .. code-block:: javascript
8181
:copyable: true
8282

83-
coll.insertMany([
83+
await coll.insertMany([
8484
{ title: 'Dangal', rating: 'Not Rated' },
8585
{ title: 'The Boss Baby', rating: 'PG' }
8686
]);

0 commit comments

Comments
 (0)