Skip to content

DOCSP-52035: Await async operations #1202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/code-snippets/indexes/compound.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ async function run() {
.find(query)
.sort(sort)
.project(projection);

for await (const doc of cursor) {
console.log(doc);
}
// end-query

} finally {
Expand Down
4 changes: 4 additions & 0 deletions source/code-snippets/indexes/multikey.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ async function run() {
const cursor = movies
.find(query)
.project(projection);

for await (const doc of cursor) {
console.log(doc);
}
// end-query

} finally {
Expand Down
4 changes: 4 additions & 0 deletions source/code-snippets/indexes/single-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ async function run() {
.find(query)
.sort(sort)
.project(projection);

for await (const doc of cursor) {
console.log(doc);
}
// end-query
} finally {
await client.close();
Expand Down
3 changes: 2 additions & 1 deletion source/code-snippets/indexes/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ async function run() {

// Execute the find operation
const cursor = myColl.find(query).project(projection);
// end-query

for await (const doc of cursor) {
console.log(doc);
}
// end-query
} finally {
await client.close();
}
Expand Down
4 changes: 2 additions & 2 deletions source/crud/query/geo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ the ``theaters`` collection using the ``createIndex()`` method:

.. code-block:: javascript

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

.. _plane:

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

.. code-block:: javascript

db.shipwrecks({coordinates: "2d"});
await db.shipwrecks.createIndex({coordinates: "2d"});

See the
:manual:`{+mdb-server+} manual page on legacy coordinate pairs </geospatial-queries/#legacy-coordinate-pairs>`
Expand Down
4 changes: 2 additions & 2 deletions source/crud/query/text.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The following examples use sample data from the ``movies`` collection in the

.. code-block:: javascript

db.movies.createIndex({ title: "text" });
await db.movies.createIndex({ title: "text" });

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

.. code-block:: javascript

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

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

Expand Down
4 changes: 2 additions & 2 deletions source/crud/update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ following:
const query = { name: "Deli Llama" };
const update = { $set: { name: "Deli Llama", address: "3 Nassau St" }};
const options = {};
myColl.updateOne(query, update, options);
const result = await myColl.updateOne(query, update, options);

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

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