From a412271942cb2484451e6ce009fb19a5c247fd18 Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 18 Jul 2025 09:59:44 -0400 Subject: [PATCH 1/3] DOCSP-52035: Await update operations --- source/crud/update.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/crud/update.txt b/source/crud/update.txt index 8855761d8..80322c14f 100644 --- a/source/crud/update.txt +++ b/source/crud/update.txt @@ -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 @@ -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 From 46e28b2b9d6a5c5d9a840789866e90c8c3529ff4 Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 18 Jul 2025 10:13:57 -0400 Subject: [PATCH 2/3] more awaits --- source/code-snippets/indexes/compound.js | 2 +- source/code-snippets/indexes/multikey.js | 2 +- source/code-snippets/indexes/single-field.js | 2 +- source/code-snippets/indexes/text.js | 5 +---- source/crud/query/geo.txt | 4 ++-- source/crud/query/text.txt | 4 ++-- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/source/code-snippets/indexes/compound.js b/source/code-snippets/indexes/compound.js index 3a8fb334e..50d97b070 100644 --- a/source/code-snippets/indexes/compound.js +++ b/source/code-snippets/indexes/compound.js @@ -31,7 +31,7 @@ async function run() { const projection = { _id: 0, type: 1, genre: 1 }; // Execute the query using the defined criteria and projection - const cursor = movies + const cursor = await movies .find(query) .sort(sort) .project(projection); diff --git a/source/code-snippets/indexes/multikey.js b/source/code-snippets/indexes/multikey.js index 4f3db0a5f..479954b83 100644 --- a/source/code-snippets/indexes/multikey.js +++ b/source/code-snippets/indexes/multikey.js @@ -26,7 +26,7 @@ async function run() { const projection = { _id: 0, cast: 1 , title: 1 }; // Perform a find operation with the preceding filter and projection - const cursor = movies + const cursor = await movies .find(query) .project(projection); // end-query diff --git a/source/code-snippets/indexes/single-field.js b/source/code-snippets/indexes/single-field.js index 41bdcbe40..bd6f1e4ca 100644 --- a/source/code-snippets/indexes/single-field.js +++ b/source/code-snippets/indexes/single-field.js @@ -25,7 +25,7 @@ async function run() { const sort = { title: 1 }; const projection = { _id: 0, title: 1 }; // Execute the query using the defined parameters - const cursor = movies + const cursor = await movies .find(query) .sort(sort) .project(projection); diff --git a/source/code-snippets/indexes/text.js b/source/code-snippets/indexes/text.js index 5c5c71599..e1558b8b8 100644 --- a/source/code-snippets/indexes/text.js +++ b/source/code-snippets/indexes/text.js @@ -33,11 +33,8 @@ async function run() { const projection = { _id: 0, title: 1 }; // Execute the find operation - const cursor = myColl.find(query).project(projection); + const cursor = await myColl.find(query).project(projection); // end-query - for await (const doc of cursor) { - console.log(doc); - } } finally { await client.close(); } diff --git a/source/crud/query/geo.txt b/source/crud/query/geo.txt index 856df7290..4e4435e81 100644 --- a/source/crud/query/geo.txt +++ b/source/crud/query/geo.txt @@ -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: @@ -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 ` diff --git a/source/crud/query/text.txt b/source/crud/query/text.txt index ae3d65200..dcd14c389 100644 --- a/source/crud/query/text.txt +++ b/source/crud/query/text.txt @@ -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 @@ -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 From 67253addb178e6a67a0704aad8e7345220303016 Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 18 Jul 2025 12:58:36 -0400 Subject: [PATCH 3/3] BP feedback --- source/code-snippets/indexes/compound.js | 6 +++++- source/code-snippets/indexes/multikey.js | 6 +++++- source/code-snippets/indexes/single-field.js | 6 +++++- source/code-snippets/indexes/text.js | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/source/code-snippets/indexes/compound.js b/source/code-snippets/indexes/compound.js index 50d97b070..bf2f097a3 100644 --- a/source/code-snippets/indexes/compound.js +++ b/source/code-snippets/indexes/compound.js @@ -31,10 +31,14 @@ async function run() { const projection = { _id: 0, type: 1, genre: 1 }; // Execute the query using the defined criteria and projection - const cursor = await movies + const cursor = movies .find(query) .sort(sort) .project(projection); + + for await (const doc of cursor) { + console.log(doc); + } // end-query } finally { diff --git a/source/code-snippets/indexes/multikey.js b/source/code-snippets/indexes/multikey.js index 479954b83..126c6a651 100644 --- a/source/code-snippets/indexes/multikey.js +++ b/source/code-snippets/indexes/multikey.js @@ -26,9 +26,13 @@ async function run() { const projection = { _id: 0, cast: 1 , title: 1 }; // Perform a find operation with the preceding filter and projection - const cursor = await movies + const cursor = movies .find(query) .project(projection); + + for await (const doc of cursor) { + console.log(doc); + } // end-query } finally { diff --git a/source/code-snippets/indexes/single-field.js b/source/code-snippets/indexes/single-field.js index bd6f1e4ca..c52285a6f 100644 --- a/source/code-snippets/indexes/single-field.js +++ b/source/code-snippets/indexes/single-field.js @@ -25,10 +25,14 @@ async function run() { const sort = { title: 1 }; const projection = { _id: 0, title: 1 }; // Execute the query using the defined parameters - const cursor = await movies + const cursor = movies .find(query) .sort(sort) .project(projection); + + for await (const doc of cursor) { + console.log(doc); + } // end-query } finally { await client.close(); diff --git a/source/code-snippets/indexes/text.js b/source/code-snippets/indexes/text.js index e1558b8b8..e67022c18 100644 --- a/source/code-snippets/indexes/text.js +++ b/source/code-snippets/indexes/text.js @@ -33,7 +33,11 @@ async function run() { const projection = { _id: 0, title: 1 }; // Execute the find operation - const cursor = await myColl.find(query).project(projection); + const cursor = myColl.find(query).project(projection); + + for await (const doc of cursor) { + console.log(doc); + } // end-query } finally { await client.close();