diff --git a/source/code-snippets/indexes/compound.js b/source/code-snippets/indexes/compound.js index 3a8fb334e..bf2f097a3 100644 --- a/source/code-snippets/indexes/compound.js +++ b/source/code-snippets/indexes/compound.js @@ -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 { diff --git a/source/code-snippets/indexes/multikey.js b/source/code-snippets/indexes/multikey.js index 4f3db0a5f..126c6a651 100644 --- a/source/code-snippets/indexes/multikey.js +++ b/source/code-snippets/indexes/multikey.js @@ -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 { diff --git a/source/code-snippets/indexes/single-field.js b/source/code-snippets/indexes/single-field.js index 41bdcbe40..c52285a6f 100644 --- a/source/code-snippets/indexes/single-field.js +++ b/source/code-snippets/indexes/single-field.js @@ -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(); diff --git a/source/code-snippets/indexes/text.js b/source/code-snippets/indexes/text.js index 5c5c71599..e67022c18 100644 --- a/source/code-snippets/indexes/text.js +++ b/source/code-snippets/indexes/text.js @@ -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(); } 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 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