Skip to content

Commit b75b39a

Browse files
committed
DOCSP-52035: Await async operations (#1202)
* DOCSP-52035: Await update operations * more awaits * BP feedback (cherry picked from commit e52710b)
1 parent 7b0a088 commit b75b39a

File tree

7 files changed

+20
-7
lines changed

7 files changed

+20
-7
lines changed

source/code-snippets/indexes/compound.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ async function run() {
3535
.find(query)
3636
.sort(sort)
3737
.project(projection);
38+
39+
for await (const doc of cursor) {
40+
console.log(doc);
41+
}
3842
// end-query
3943

4044
} finally {

source/code-snippets/indexes/multikey.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ async function run() {
2929
const cursor = movies
3030
.find(query)
3131
.project(projection);
32+
33+
for await (const doc of cursor) {
34+
console.log(doc);
35+
}
3236
// end-query
3337

3438
} finally {

source/code-snippets/indexes/single-field.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ async function run() {
2929
.find(query)
3030
.sort(sort)
3131
.project(projection);
32+
33+
for await (const doc of cursor) {
34+
console.log(doc);
35+
}
3236
// end-query
3337
} finally {
3438
await client.close();

source/code-snippets/indexes/text.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ async function run() {
3434

3535
// Execute the find operation
3636
const cursor = myColl.find(query).project(projection);
37-
// end-query
37+
3838
for await (const doc of cursor) {
3939
console.log(doc);
4040
}
41+
// end-query
4142
} finally {
4243
await client.close();
4344
}

source/crud/query/geo.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ the ``theaters`` collection using the ``createIndex()`` method:
6666

6767
.. code-block:: javascript
6868

69-
db.theaters.createIndex({location.geo: "2dsphere"});
69+
await db.theaters.createIndex({location.geo: "2dsphere"});
7070

7171
.. _plane:
7272

@@ -94,7 +94,7 @@ the field on the collection. The following snippet creates an index on the
9494

9595
.. code-block:: javascript
9696

97-
db.shipwrecks({coordinates: "2d"});
97+
await db.shipwrecks.createIndex({coordinates: "2d"});
9898

9999
See the
100100
:manual:`{+mdb-server+} manual page on legacy coordinate pairs </geospatial-queries/#legacy-coordinate-pairs>`

source/crud/query/text.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The following examples use sample data from the ``movies`` collection in the
4141

4242
.. code-block:: javascript
4343

44-
db.movies.createIndex({ title: "text" });
44+
await db.movies.createIndex({ title: "text" });
4545

4646
We use a single field text index for the examples in this guide, but you can
4747
create a compound text index that broadens your text queries to multiple
@@ -50,7 +50,7 @@ fields. The following command creates a text index on two fields in the
5050

5151
.. code-block:: javascript
5252

53-
db.movies.createIndex({ title: "text", plot: "text" });
53+
await db.movies.createIndex({ title: "text", plot: "text" });
5454

5555
.. tip:: Specify Field Weights in a Text Index
5656

source/crud/update.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ following:
7373
const query = { name: "Deli Llama" };
7474
const update = { $set: { name: "Deli Llama", address: "3 Nassau St" }};
7575
const options = {};
76-
myColl.updateOne(query, update, options);
76+
const result = await myColl.updateOne(query, update, options);
7777

7878
If a food truck named "Deli Llama" exists, the method call above updates
7979
the document in the collection. However, if there are no food trucks named
@@ -96,7 +96,7 @@ update the document, we can set ``upsert`` to ``true`` in our call to
9696
const query = { name: "Deli Llama" };
9797
const update = { $set: { name: "Deli Llama", address: "3 Nassau St" }};
9898
const options = { upsert: true };
99-
myColl.updateOne(query, update, options);
99+
const result = await myColl.updateOne(query, update, options);
100100

101101
After you run the operation above, your collection looks similar to the
102102
following, even if the ``"Deli Llama"`` document did not exist in your collection

0 commit comments

Comments
 (0)