From ee7d4236fded9a1f864843593262fd9ea2831756 Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 27 Mar 2025 16:42:18 -0400 Subject: [PATCH 1/2] move sync above async --- .../crud/read-operations/change-streams.txt | 92 +++++----- .../crud/read-operations/distinct.txt | 62 +++---- .../crud/read-operations/retrieve.txt | 36 ++-- .../crud/write-operations/bulk-write.txt | 41 +++-- .../crud/write-operations/delete.txt | 34 ++-- .../crud/write-operations/insert.txt | 40 +++-- source/fundamentals/database-collection.txt | 157 +++++++++--------- .../databases-collections/run-command.txt | 64 ++++--- source/usage-examples/deleteMany.txt | 28 ++-- source/usage-examples/deleteOne.txt | 28 ++-- source/usage-examples/findMany.txt | 88 +++++----- source/usage-examples/findOne.txt | 40 ++--- source/usage-examples/insertMany.txt | 22 +-- source/usage-examples/insertOne.txt | 29 ++-- source/usage-examples/replaceOne.txt | 28 ++-- source/usage-examples/updateMany.txt | 28 ++-- source/usage-examples/updateOne.txt | 27 ++- 17 files changed, 414 insertions(+), 430 deletions(-) diff --git a/source/fundamentals/crud/read-operations/change-streams.txt b/source/fundamentals/crud/read-operations/change-streams.txt index 77231220..df8de764 100644 --- a/source/fundamentals/crud/read-operations/change-streams.txt +++ b/source/fundamentals/crud/read-operations/change-streams.txt @@ -65,20 +65,12 @@ classes: - ``Collection``: To monitor changes in the collection The following example opens a change stream on the ``restaurants`` collection -and outputs the changes as they occur. Select the -:guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the corresponding +and outputs the changes as they occur. Select the :guilabel:`Synchronous` or +:guilabel:`Asynchronous` to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: change-stream-async - - .. literalinclude:: /includes/code-examples/change-streams/change-streams.cs - :start-after: start-open-change-stream-async - :end-before: end-open-change-stream-async - :language: csharp - .. tab:: Synchronous :tabid: change-stream-sync @@ -87,6 +79,14 @@ code. :end-before: end-open-change-stream :language: csharp + .. tab:: Asynchronous + :tabid: change-stream-async + + .. literalinclude:: /includes/code-examples/change-streams/change-streams.cs + :start-after: start-open-change-stream-async + :end-before: end-open-change-stream-async + :language: csharp + To begin watching for changes, run the application. Then, in a separate application or shell, modify the ``restaurants`` collection. Updating a document that has a ``"name"`` value of ``"Blarney Castle"`` results in the following @@ -134,20 +134,12 @@ You can specify the following aggregation stages in the ``pipeline`` parameter: Monitor Update Events Example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The following example uses the ``pipeline`` parameter to open a change stream -that records only update operations. Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the -corresponding code. +The following example uses the ``pipeline`` parameter to open a change stream that records +only update operations. Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab +to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: change-stream-async - - .. literalinclude:: /includes/code-examples/change-streams/change-streams.cs - :start-after: start-change-stream-pipeline-async - :end-before: end-change-stream-pipeline-async - :language: csharp - .. tab:: Synchronous :tabid: change-stream-sync @@ -156,6 +148,14 @@ corresponding code. :end-before: end-change-stream-pipeline :language: csharp + .. tab:: Asynchronous + :tabid: change-stream-async + + .. literalinclude:: /includes/code-examples/change-streams/change-streams.cs + :start-after: start-change-stream-pipeline-async + :end-before: end-change-stream-pipeline-async + :language: csharp + Split Large Change Events Example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -173,14 +173,6 @@ reassemble any event fragments: .. tabs:: - .. tab:: Asynchronous - :tabid: change-stream-split-async - - .. literalinclude:: /includes/code-examples/change-streams/change-streams.cs - :start-after: start-split-change-event-async - :end-before: end-split-change-event-async - :language: csharp - .. tab:: Synchronous :tabid: change-stream-split-sync @@ -189,6 +181,14 @@ reassemble any event fragments: :end-before: end-split-change-event-sync :language: csharp + .. tab:: Asynchronous + :tabid: change-stream-split-async + + .. literalinclude:: /includes/code-examples/change-streams/change-streams.cs + :start-after: start-split-change-event-async + :end-before: end-split-change-event-async + :language: csharp + .. note:: We recommend reassembling change event fragments, as shown in the @@ -202,6 +202,14 @@ The following code defines these methods: .. tabs:: + .. tab:: Synchronous + :tabid: split-event-helpers-sync + + .. literalinclude:: /includes/code-examples/change-streams/change-streams.cs + :start-after: start-split-event-helpers-sync + :end-before: end-split-event-helpers-sync + :language: csharp + .. tab:: Asynchronous :tabid: split-event-helpers-async @@ -210,14 +218,6 @@ The following code defines these methods: :end-before: end-split-event-helpers-async :language: csharp - .. tab:: Synchronous - :tabid: split-event-helpers-sync - - .. literalinclude:: /includes/code-examples/change-streams/change-streams.cs - :start-after: start-split-event-helpers-sync - :end-before: end-split-event-helpers-sync - :language: csharp - .. tip:: To learn more about splitting large change events, see @@ -344,19 +344,11 @@ one of the following values: The following example opens a change stream on a collection and includes the post-image of updated documents by specifying the ``FullDocument`` option. Select the -:guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the corresponding +:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: change-stream-async - - .. literalinclude:: /includes/code-examples/change-streams/change-streams.cs - :start-after: start-change-stream-post-image-async - :end-before: end-change-stream-post-image-async - :language: csharp - .. tab:: Synchronous :tabid: change-stream-sync @@ -365,6 +357,14 @@ code. :end-before: end-change-stream-post-image :language: csharp + .. tab:: Asynchronous + :tabid: change-stream-async + + .. literalinclude:: /includes/code-examples/change-streams/change-streams.cs + :start-after: start-change-stream-post-image-async + :end-before: end-change-stream-post-image-async + :language: csharp + Running the preceding code example and updating a document that has a ``"name"`` value of ``"Blarney Castle"`` results in the following change stream output: diff --git a/source/fundamentals/crud/read-operations/distinct.txt b/source/fundamentals/crud/read-operations/distinct.txt index 743609ae..326c187c 100644 --- a/source/fundamentals/crud/read-operations/distinct.txt +++ b/source/fundamentals/crud/read-operations/distinct.txt @@ -56,20 +56,20 @@ Retrieve Values Across a Collection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The following example retrieves the distinct values of the ``borough`` field in -the ``restaurants`` collection. Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` +the ``restaurants`` collection. Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: distinct-async + .. tab:: Synchronous + :tabid: distinct-sync .. io-code-block:: :copyable: .. input:: /includes/fundamentals/code-examples/Distinct.cs - :start-after: start-distinct-async - :end-before: end-distinct-async + :start-after: start-distinct + :end-before: end-distinct :language: csharp :dedent: @@ -83,15 +83,15 @@ tab to see the corresponding code. Queens Staten Island - .. tab:: Synchronous - :tabid: distinct-sync + .. tab:: Asynchronous + :tabid: distinct-async .. io-code-block:: :copyable: .. input:: /includes/fundamentals/code-examples/Distinct.cs - :start-after: start-distinct - :end-before: end-distinct + :start-after: start-distinct-async + :end-before: end-distinct-async :language: csharp :dedent: @@ -119,19 +119,19 @@ For more information about creating a query filter, see the :ref:`csharp-specify The following example retrieves the distinct values of the ``borough`` field for all documents that have a ``cuisine`` field value of ``"Italian"``. Select the -:guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the corresponding code. +:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - - .. tab:: Asynchronous - :tabid: distinct-async + + .. tab:: Synchronous + :tabid: distinct-sync .. io-code-block:: :copyable: .. input:: /includes/fundamentals/code-examples/Distinct.cs - :start-after: start-distinct-with-query-async - :end-before: end-distinct-with-query-async + :start-after: start-distinct-with-query + :end-before: end-distinct-with-query :language: csharp :dedent: @@ -143,16 +143,16 @@ all documents that have a ``cuisine`` field value of ``"Italian"``. Select the Manhattan Queens Staten Island - - .. tab:: Synchronous - :tabid: distinct-sync + + .. tab:: Asynchronous + :tabid: distinct-async .. io-code-block:: :copyable: .. input:: /includes/fundamentals/code-examples/Distinct.cs - :start-after: start-distinct-with-query - :end-before: end-distinct-with-query + :start-after: start-distinct-with-query-async + :end-before: end-distinct-with-query-async :language: csharp :dedent: @@ -196,20 +196,20 @@ all documents that have a ``borough`` field value of ``"Bronx"`` and a ``cuisine`` field value of ``"Pizza"``. Then, it adds a comment to the operation by providing a ``DistinctOptions`` instance to the ``Distinct()`` method. -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - - .. tab:: Asynchronous - :tabid: distinct-async + + .. tab:: Synchronous + :tabid: distinct-sync .. io-code-block:: :copyable: .. input:: /includes/fundamentals/code-examples/Distinct.cs - :start-after: start-distinct-with-comment-async - :end-before: end-distinct-with-comment-async + :start-after: start-distinct-with-comment + :end-before: end-distinct-with-comment :language: csharp :dedent: @@ -224,16 +224,16 @@ corresponding code. Amici Pizza And Pasta Angie'S Cafe Pizza ... - - .. tab:: Synchronous - :tabid: distinct-sync + + .. tab:: Asynchronous + :tabid: distinct-async .. io-code-block:: :copyable: .. input:: /includes/fundamentals/code-examples/Distinct.cs - :start-after: start-distinct-with-comment - :end-before: end-distinct-with-comment + :start-after: start-distinct-with-comment-async + :end-before: end-distinct-with-comment-async :language: csharp :dedent: diff --git a/source/fundamentals/crud/read-operations/retrieve.txt b/source/fundamentals/crud/read-operations/retrieve.txt index 45612a44..c8eba926 100644 --- a/source/fundamentals/crud/read-operations/retrieve.txt +++ b/source/fundamentals/crud/read-operations/retrieve.txt @@ -86,21 +86,21 @@ results. If no documents match the query filter the methods return ``null``. .. tabs:: - .. tab:: Asynchronous - :tabid: find-one-async + .. tab:: Synchronous + :tabid: find-one-sync .. code-block:: csharp :copyable: true - var restaurants = await _restaurantsCollection.Find(filter).FirstOrDefaultAsync(); + var restaurants = _restaurantsCollection.Find(filter).FirstOrDefault(); - .. tab:: Synchronous - :tabid: find-one-sync + .. tab:: Asynchronous + :tabid: find-one-async .. code-block:: csharp :copyable: true - var restaurants = _restaurantsCollection.Find(filter).FirstOrDefault(); + var restaurants = await _restaurantsCollection.Find(filter).FirstOrDefaultAsync(); .. tip:: First Document @@ -133,21 +133,21 @@ To view a synchronous or asynchronous example, select the corresponding tab. .. tabs:: - .. tab:: Asynchronous - :tabid: find-cursor-async + .. tab:: Synchronous + :tabid: find-cursor-sync .. code-block:: csharp :copyable: true - var restaurants = await _restaurantsCollection.Find(filter).ToCursorAsync(); + var restaurants = _restaurantsCollection.Find(filter).ToCursor(); - .. tab:: Synchronous - :tabid: find-cursor-sync + .. tab:: Asynchronous + :tabid: find-cursor-async .. code-block:: csharp :copyable: true - var restaurants = _restaurantsCollection.Find(filter).ToCursor(); + var restaurants = await _restaurantsCollection.Find(filter).ToCursorAsync(); If you are returning a small number of documents, or need your results returned as a ``List`` object, use the ``ToList()`` or ``ToListAsync()`` methods. @@ -159,19 +159,19 @@ synchronous or asynchronous example, select the corresponding tab. .. tabs:: - .. tab:: Asynchronous - :tabid: find-list-async + .. tab:: Synchronous + :tabid: find-list-sync .. code-block:: csharp - var restaurants = await _restaurantsCollection.Find(filter).ToListAsync(); + var restaurants = _restaurantsCollection.Find(filter).ToList(); - .. tab:: Synchronous - :tabid: find-list-sync + .. tab:: Asynchronous + :tabid: find-list-async .. code-block:: csharp - var restaurants = _restaurantsCollection.Find(filter).ToList(); + var restaurants = await _restaurantsCollection.Find(filter).ToListAsync(); To see a full example of using the ``Find()`` method to find multiple documents, see :ref:`csharp-retrieve-additional-information`. diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index 37346e76..4df46aa6 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -356,28 +356,27 @@ the operations in the order they're defined in the collection. ``Array`` and ``List`` are two common classes that implement the ``IReadOnlyList`` interface. -Select from the following tabs to view how to use the asynchronous -``BulkWriteAsync()`` method and the synchronous ``BulkWrite()`` method to -perform a bulk write operation. +Select from the following tabs to view how to use the synchronous ``BulkWrite()`` method +and the asynchronous ``BulkWriteAsync()`` method to perform a bulk write operation. .. tabs:: - .. tab:: Asynchronous - :tabid: bulk-write-async + .. tab:: Synchronous + :tabid: bulk-write-sync .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs - :start-after: start-bulk-write-async - :end-before: end-bulk-write-async + :start-after: start-bulk-write-sync + :end-before: end-bulk-write-sync :language: csharp :copyable: :dedent: 8 - .. tab:: Synchronous - :tabid: bulk-write-sync + .. tab:: Asynchronous + :tabid: bulk-write-async .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs - :start-after: start-bulk-write-sync - :end-before: end-bulk-write-sync + :start-after: start-bulk-write-async + :end-before: end-bulk-write-async :language: csharp :copyable: :dedent: 8 @@ -450,16 +449,6 @@ a delete operation: .. tabs:: - .. tab:: Asynchronous - :tabid: bulk-write-options-async - - .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs - :start-after: start-bulk-write-options-async - :end-before: end-bulk-write-options-async - :language: csharp - :copyable: - :dedent: 8 - .. tab:: Synchronous :tabid: bulk-write-options-sync @@ -470,6 +459,16 @@ a delete operation: :copyable: :dedent: 8 + .. tab:: Asynchronous + :tabid: bulk-write-options-async + + .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs + :start-after: start-bulk-write-options-async + :end-before: end-bulk-write-options-async + :language: csharp + :copyable: + :dedent: 8 + Return Value ------------ diff --git a/source/fundamentals/crud/write-operations/delete.txt b/source/fundamentals/crud/write-operations/delete.txt index 5d26c3c1..4c679bd4 100644 --- a/source/fundamentals/crud/write-operations/delete.txt +++ b/source/fundamentals/crud/write-operations/delete.txt @@ -62,52 +62,50 @@ delete operations in MongoDB with the following methods: Delete One Document ~~~~~~~~~~~~~~~~~~~ -The following code shows how to use the asynchronous -``DeleteOneAsync()`` method or the synchronous ``DeleteOne()`` method to -delete one document. +The following code shows how to use the synchronous ``DeleteOne()`` method or the asynchronous +``DeleteOneAsync()`` method to delete one document. .. tabs:: - .. tab:: Asynchronous - :tabid: delete-one-async + .. tab:: Synchronous + :tabid: delete-one-sync .. code-block:: csharp :copyable: true - var result = await _restaurantsCollection.DeleteOneAsync(filter); + var result = _restaurantsCollection.DeleteOne(filter); - .. tab:: Synchronous - :tabid: delete-one-sync + .. tab:: Asynchronous + :tabid: delete-one-async .. code-block:: csharp :copyable: true - var result = _restaurantsCollection.DeleteOne(filter); + var result = await _restaurantsCollection.DeleteOneAsync(filter); Delete Multiple Documents ~~~~~~~~~~~~~~~~~~~~~~~~~ -The following code shows how to use the asynchronous -``DeleteManyAsync()`` method or the synchronous ``DeleteMany()`` method to -delete all matched documents. +The following code shows how to use the synchronous ``DeleteMany()`` method or the asynchronous +``DeleteManyAsync()`` method to delete all matched documents. .. tabs:: - .. tab:: Asynchronous - :tabid: delete-many-async + .. tab:: Synchronous + :tabid: delete-many-sync .. code-block:: csharp :copyable: true - var result = await _restaurantsCollection.DeleteManyAsync(filter); + var result = _restaurantsCollection.DeleteMany(filter); - .. tab:: Synchronous - :tabid: delete-many-sync + .. tab:: Asynchronous + :tabid: delete-many-async .. code-block:: csharp :copyable: true - var result = _restaurantsCollection.DeleteMany(filter); + var result = await _restaurantsCollection.DeleteManyAsync(filter); .. tip:: diff --git a/source/fundamentals/crud/write-operations/insert.txt b/source/fundamentals/crud/write-operations/insert.txt index be425c41..db562689 100644 --- a/source/fundamentals/crud/write-operations/insert.txt +++ b/source/fundamentals/crud/write-operations/insert.txt @@ -30,10 +30,10 @@ documents to a MongoDB collection by performing insert operations. An insert operation inserts one or more documents into a MongoDB collection. The {+driver-short+} provides the following methods to perform insert -operations, each of which has an asynchronous and synchronous version: +operations, each of which has a synchronous and asynchronous version: -- ``InsertOneAsync()`` or ``InsertOne()`` -- ``InsertManyAsync()`` or ``InsertMany()`` +- ``InsertOne() or ``InsertOneAsync()`` +- ``InsertMany()`` or ``InsertManyAsync()`` .. tip:: Interactive Lab @@ -108,52 +108,50 @@ Server Manual Entry on :manual:`Documents `. Insert One Document ------------------- -The following code shows how to use the asynchronous -``InsertOneAsync()`` method or the synchronous ``InsertOne()`` method to -insert one document. +The following code shows how to use the synchronous ``InsertOne()`` method or the asynchronous +``InsertOneAsync()`` method to insert one document. .. tabs:: - .. tab:: Asynchronous - :tabid: insert-one-async + .. tab:: Synchronous + :tabid: insert-one-sync .. code-block:: csharp :copyable: true - await _restaurantsCollection.InsertOneAsync(document); + _restaurantsCollection.InsertOne(document); - .. tab:: Synchronous - :tabid: insert-one-sync + .. tab:: Asynchronous + :tabid: insert-one-async .. code-block:: csharp :copyable: true - _restaurantsCollection.InsertOne(document); + await _restaurantsCollection.InsertOneAsync(document); Insert Multiple Documents ------------------------- -The following code shows how to use the asynchronous -``InsertManyAsync()`` method or the synchronous ``InsertMany()`` method to -insert multiple documents. +The following code shows how to use the synchronous ``InsertMany()`` method or the asynchronous +``InsertManyAsync()`` method to insert multiple documents. .. tabs:: - .. tab:: Asynchronous - :tabid: insert-many-async + .. tab:: Synchronous + :tabid: insert-many-sync .. code-block:: csharp :copyable: true - await _restaurantsCollection.InsertManyAsync(docs); + _restaurantsCollection.InsertMany(docs); - .. tab:: Synchronous - :tabid: insert-many-sync + .. tab:: Asynchronous + :tabid: insert-many-async .. code-block:: csharp :copyable: true - _restaurantsCollection.InsertMany(docs); + await _restaurantsCollection.InsertManyAsync(docs); .. tip:: diff --git a/source/fundamentals/database-collection.txt b/source/fundamentals/database-collection.txt index 919d9e03..4af4a3ac 100644 --- a/source/fundamentals/database-collection.txt +++ b/source/fundamentals/database-collection.txt @@ -69,69 +69,57 @@ method to access a database called ``test_db``: List Databases -------------- -To see a list of your deployment's databases, call the -asynchronous `ListDatabaseNamesAsync() +To see a list of your deployment's databases, call the synchronous `ListDatabaseNames() +<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.ListDatabaseNames.html>`__ +method or asynchronous `ListDatabaseNamesAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.ListDatabaseNamesAsync.html>`__ -method or synchronous `ListDatabaseNames() -<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.ListDatabaseNames.html>`__ method on -your ``IMongoClient`` instance. +method on your ``IMongoClient`` instance. -To see detailed information about each database, call the +To see detailed information about each database, call the synchronous `ListDatabases() +<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.ListDatabases.html>`__ method or asynchronous `ListDatabasesAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.ListDatabasesAsync.html>`__ -method or synchronous `ListDatabases() -<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.ListDatabases.html>`__ method on -your ``IMongoClient`` instance. These methods return fields describing +method on your ``IMongoClient`` instance. These methods return fields describing the databases in the cluster, such as their sizes and whether they contain data. -The following code shows how to use the asynchronous -``ListDatabaseNamesAsync()`` method or the synchronous ``ListDatabaseNames()`` method to -list the names of the databases in a cluster: +The following code shows how to use the synchronous ``ListDatabaseNames()`` method or the +asynchronous ``ListDatabaseNamesAsync()`` method to list the names of the databases in a +cluster: .. tabs:: - .. tab:: Asynchronous - :tabid: list-db-async + .. tab:: Synchronous + :tabid: list-db-sync .. code-block:: csharp :copyable: true - await mongoClient.ListDatabaseNamesAsync(); + mongoClient.ListDatabaseNames(); - .. tab:: Synchronous - :tabid: list-db-sync + .. tab:: Asynchronous + :tabid: list-db-async .. code-block:: csharp :copyable: true - mongoClient.ListDatabaseNames(); + await mongoClient.ListDatabaseNamesAsync(); Drop a Database --------------- Dropping a database permanently deletes all the data in that database's -collections. To drop a database, call the -asynchronous `DropDatabaseAsync() -<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.DropDatabaseAsync.html>`__ -method or synchronous `DropDatabase() +collections. To drop a database, call the synchronous `DropDatabase() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.DropDatabase.html>`__ +method or asynchronous `DropDatabaseAsync() +<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.DropDatabaseAsync.html>`__ method on your ``IMongoClient`` instance, passing the database name as the parameter. -The following code shows how to use the asynchronous -``DropDatabaseAsync()`` method or the synchronous ``DropDatabase()`` method to -drop a database called ``test_db``: +The following code shows how to use the synchronous ``DropDatabase()`` method or the asynchronous +``DropDatabaseAsync()`` method to drop a database called ``test_db``: .. tabs:: - .. tab:: Asynchronous - :tabid: drop-db-async - - .. code-block:: csharp - :copyable: true - - await mongoClient.DropDatabaseAsync("test_db"); - .. tab:: Synchronous :tabid: drop-db-sync @@ -140,6 +128,14 @@ drop a database called ``test_db``: mongoClient.DropDatabase("test_db"); + .. tab:: Asynchronous + :tabid: drop-db-async + + .. code-block:: csharp + :copyable: true + + await mongoClient.DropDatabaseAsync("test_db"); + .. warning:: Dropping a Database Deletes Data Dropping a database permanently deletes all @@ -207,11 +203,10 @@ collection with the ``BsonDocument`` type: Create a Collection ------------------- -You can explicitly create a collection by calling the -asynchronous `CreateCollectionAsync() -<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.CreateCollectionAsync.html>`__ -method or synchronous `CreateCollection() +You can explicitly create a collection by calling the synchronous `CreateCollection() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.CreateCollection.html>`__ +method or asynchronous `CreateCollectionAsync() +<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.CreateCollectionAsync.html>`__ method on your ``IMongoDatabase`` instance. This method takes the collection name and an @@ -220,21 +215,13 @@ optional `CreateCollectionOptions parameters. You can then access the created collection to perform data operations, create aggregations, and manage indexes. -The following code shows how to use the asynchronous -``CreateCollectionAsync()`` method or the synchronous -``CreateCollection()`` method to create a collection called +The following code shows how to use the synchronous +``CreateCollection()`` method or the asynchronous +``CreateCollectionAsync()`` method to create a collection called ``coll_abc`` within a database referenced by the ``myDB`` variable: .. tabs:: - .. tab:: Asynchronous - :tabid: create-coll-async - - .. code-block:: csharp - :copyable: true - - await myDB.CreateCollectionAsync("coll_abc"); - .. tab:: Synchronous :tabid: create-coll-sync @@ -243,72 +230,69 @@ The following code shows how to use the asynchronous myDB.CreateCollection("coll_abc"); + .. tab:: Asynchronous + :tabid: create-coll-async + + .. code-block:: csharp + :copyable: true + + await myDB.CreateCollectionAsync("coll_abc"); + List Collections ---------------- -To see a list of collections in a database, call the -asynchronous `ListCollectionNamesAsync() +To see a list of collections in a database, call the synchronous `ListCollectionNames() +<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.ListCollectionNames.html>`__ +method or asynchronous `ListCollectionNamesAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.ListCollectionNamesAsync.html>`__ -method or synchronous `ListCollectionNames() -<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.ListCollectionNames.html>`__ method on -your ``IMongoDatabase`` instance. +method on your ``IMongoDatabase`` instance. -To see detailed information about each database, call the -asynchronous `ListCollectionsAsync() +To see detailed information about each database, call the synchronous `ListCollections() +<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.ListCollections.html>`__ +method or asynchronous `ListCollectionsAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.ListCollectionsAsync.html>`__ -method or synchronous `ListCollections() -<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.ListCollections.html>`__ method on -your ``IMongoDatabase`` instance. These methods return fields describing +method on your ``IMongoDatabase`` instance. These methods return fields describing the collections in the database, such as their types and settings. -The following code shows how to use the asynchronous -``ListCollectionNamesAsync()`` method or the synchronous ``ListCollectionNames()`` method to -list the names of the collections in a database: +The following code shows how to use the synchronous ``ListCollectionNames()`` method or +the asynchronous ``ListCollectionNamesAsync()`` method to list the names of the +collections in a database: .. tabs:: - .. tab:: Asynchronous - :tabid: list-coll-async + .. tab:: Synchronous + :tabid: list-coll-sync .. code-block:: csharp :copyable: true - await myDB.ListCollectionNamesAsync(); + myDB.ListCollectionNames(); - .. tab:: Synchronous - :tabid: list-coll-sync + .. tab:: Asynchronous + :tabid: list-coll-async .. code-block:: csharp :copyable: true - myDB.ListCollectionNames(); + await myDB.ListCollectionNamesAsync(); .. _csharp-drop-collection: Drop a Collection ----------------- -Dropping a collection permanently deletes all the data in that -collection. To drop a collection, call the asynchronous `DropCollectionAsync() -<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.DropCollectionAsync.html>`__ method or the -synchronous `DropCollection() -<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.DropCollection.html>`__ +Dropping a collection permanently deletes all the data in that collection. To drop a +collection, call the synchronous `DropCollection() +<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.DropCollection.html>`__ or +the asynchronous `DropCollectionAsync() +<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoDatabase.DropCollectionAsync.html>`__ method on your ``IMongoCollection`` instance. -The following code shows how to use the asynchronous -``DropCollectionAsync()`` method or the synchronous ``DropCollection()`` method to -drop a database called ``coll_abc``: +The following code shows how to use the synchronous ``DropCollection()`` method or the asynchronous +``DropCollectionAsync()`` method to drop a database called ``coll_abc``: .. tabs:: - .. tab:: Asynchronous - :tabid: drop-coll-async - - .. code-block:: csharp - :copyable: true - - await myDB.DropCollectionAsync("coll_abc"); - .. tab:: Synchronous :tabid: drop-coll-sync @@ -316,6 +300,13 @@ drop a database called ``coll_abc``: :copyable: true myDB.DropCollection("coll_abc"); + .. tab:: Asynchronous + :tabid: drop-coll-async + + .. code-block:: csharp + :copyable: true + + await myDB.DropCollectionAsync("coll_abc"); .. warning:: Dropping a Collection Deletes Data diff --git a/source/fundamentals/databases-collections/run-command.txt b/source/fundamentals/databases-collections/run-command.txt index fbf020a8..28312d91 100644 --- a/source/fundamentals/databases-collections/run-command.txt +++ b/source/fundamentals/databases-collections/run-command.txt @@ -47,7 +47,6 @@ The examples in this guide use the ``sample_restaurants.restaurants`` collection from the :atlas:`Atlas sample datasets `. To learn how to create a free MongoDB Atlas cluster and load the sample datasets, see the :ref:``. - Execute a Command ----------------- @@ -58,28 +57,28 @@ You can use the ``BsonDocument`` type to return the command response, or you can own strongly typed class to deserialize the command response. The following example runs the ``hello`` command on a database, which returns information -about the server. Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` -tab to see the corresponding code. +about the server. Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to +see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: run-command-async + .. tab:: Synchronous + :tabid: distinct-sync .. literalinclude:: /includes/fundamentals/code-examples/databases-collections/RunCommand.cs :language: csharp :dedent: - :start-after: start-hello-async - :end-before: end-hello-async + :start-after: start-hello + :end-before: end-hello - .. tab:: Synchronous - :tabid: distinct-sync + .. tab:: Asynchronous + :tabid: run-command-async .. literalinclude:: /includes/fundamentals/code-examples/databases-collections/RunCommand.cs :language: csharp :dedent: - :start-after: start-hello - :end-before: end-hello + :start-after: start-hello-async + :end-before: end-hello-async .. tip:: @@ -96,21 +95,11 @@ The ``RunCommand()`` method does not inherit the read preference you might have set on your ``MongoDatabase`` instance. By default, ``RunCommand()`` uses the ``primary`` read preference. -You can set a read preference for the command execution by passing a -``ReadPreference`` instance as a parameter to ``RunCommand()``, as -shown in the following example. Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` -tab to see the corresponding code. +You can set a read preference for the command execution by passing a ``ReadPreference`` +instance as a parameter to ``RunCommand()``, as shown in the following example. Select the +:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - - .. tab:: Asynchronous - :tabid: run-command-async - - .. literalinclude:: /includes/fundamentals/code-examples/databases-collections/RunCommand.cs - :language: csharp - :dedent: - :start-after: start-read-pref-async - :end-before: end-read-pref-async .. tab:: Synchronous :tabid: distinct-sync @@ -121,6 +110,15 @@ tab to see the corresponding code. :start-after: start-read-pref :end-before: end-read-pref + .. tab:: Asynchronous + :tabid: run-command-async + + .. literalinclude:: /includes/fundamentals/code-examples/databases-collections/RunCommand.cs + :language: csharp + :dedent: + :start-after: start-read-pref-async + :end-before: end-read-pref-async + .. tip:: To learn more about read preference options, see :manual:`Read @@ -170,28 +168,28 @@ Example The following example runs the ``dbStats`` command to retrieve storage statistics for the ``sample_restaurants`` database, then prints the command results by using the ``ToJson()`` method on the returned ``BsonDocument`` object. -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the corresponding +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: run-command-async + .. tab:: Synchronous + :tabid: distinct-sync .. literalinclude:: /includes/fundamentals/code-examples/databases-collections/RunCommand.cs :language: csharp :dedent: - :start-after: start-print-command-async - :end-before: end-print-command-async + :start-after: start-print-command + :end-before: end-print-command - .. tab:: Synchronous - :tabid: distinct-sync + .. tab:: Asynchronous + :tabid: run-command-async .. literalinclude:: /includes/fundamentals/code-examples/databases-collections/RunCommand.cs :language: csharp :dedent: - :start-after: start-print-command - :end-before: end-print-command + :start-after: start-print-command-async + :end-before: end-print-command-async The output of this command includes information about the data stored in the database, as shown in the result returned by the previous example: diff --git a/source/usage-examples/deleteMany.txt b/source/usage-examples/deleteMany.txt index 96103487..952ad41c 100644 --- a/source/usage-examples/deleteMany.txt +++ b/source/usage-examples/deleteMany.txt @@ -26,24 +26,11 @@ Example The following code deletes all documents in the ``restaurants`` collection whose ``borough`` field value equals the word "Brooklyn". -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the corresponding +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: delete-many-async - - .. literalinclude:: ../includes/code-examples/delete-many/DeleteManyAsync.cs - :start-after: start-delete-many-async - :end-before: end-delete-many-async - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of the ``DeleteManyAsync()`` operation, see the - `DeleteManyAsync code sample <{+example+}/delete-many/DeleteManyAsync.cs>`__. - .. tab:: Synchronous :tabid: delete-many-sync @@ -57,6 +44,19 @@ code. For a fully runnable example of the ``DeleteMany()`` operation, see the `DeleteMany code sample <{+example+}/delete-many/DeleteMany.cs>`__. + .. tab:: Asynchronous + :tabid: delete-many-async + + .. literalinclude:: ../includes/code-examples/delete-many/DeleteManyAsync.cs + :start-after: start-delete-many-async + :end-before: end-delete-many-async + :language: csharp + :copyable: + :dedent: + + For a fully runnable example of the ``DeleteManyAsync()`` operation, see the + `DeleteManyAsync code sample <{+example+}/delete-many/DeleteManyAsync.cs>`__. + Expected Result ~~~~~~~~~~~~~~~ diff --git a/source/usage-examples/deleteOne.txt b/source/usage-examples/deleteOne.txt index edd66963..b760395f 100644 --- a/source/usage-examples/deleteOne.txt +++ b/source/usage-examples/deleteOne.txt @@ -36,24 +36,11 @@ Delete a Document by Using Builders The following example uses ``Builders`` to delete a document in the ``restaurants`` collection with the ``name`` "Ready Penny Inn". -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: builders-async - - .. literalinclude:: ../includes/code-examples/delete-one/DeleteOneAsync.cs - :start-after: start-delete-one-builders-async - :end-before: end-delete-one-builders-async - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of the ``DeleteOne()`` method, see the - `Asynchronous Delete One Example <{+example+}/delete-one/DeleteOneAsync.cs>`__. - .. tab:: Synchronous :tabid: builders-sync @@ -67,6 +54,19 @@ corresponding code. For a fully runnable example of the ``DeleteOne()`` method, see the `Synchronous Delete One Example <{+example+}/delete-one/DeleteOne.cs>`__ + .. tab:: Asynchronous + :tabid: builders-async + + .. literalinclude:: ../includes/code-examples/delete-one/DeleteOneAsync.cs + :start-after: start-delete-one-builders-async + :end-before: end-delete-one-builders-async + :language: csharp + :copyable: + :dedent: + + For a fully runnable example of the ``DeleteOne()`` method, see the + `Asynchronous Delete One Example <{+example+}/delete-one/DeleteOneAsync.cs>`__. + Expected Result ~~~~~~~~~~~~~~~ diff --git a/source/usage-examples/findMany.txt b/source/usage-examples/findMany.txt index 81cb98f6..4236f3c1 100644 --- a/source/usage-examples/findMany.txt +++ b/source/usage-examples/findMany.txt @@ -29,25 +29,11 @@ Find Documents by Using Builders The following example uses ``Builders`` to find documents in the ``restaurants`` collection with the ``cuisine`` "Pizza". -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: builders-async - - .. literalinclude:: ../includes/code-examples/find-many/FindManyAsync.cs - :start-after: start-find-builders-async - :end-before: end-find-builders-async - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of using the ``Find()`` method to asynchronously - find multiple documents, see - `Asynchronous Find Multiple Example <{+example+}/find-many/FindManyAsync.cs>`__. - .. tab:: Synchronous :tabid: builders-sync @@ -62,23 +48,12 @@ corresponding code. find multiple documents, see `Synchronous Find Multiple Example <{+example+}/find-many/FindMany.cs>`__. -Find Documents by Using LINQ -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The following example uses LINQ to find documents in the -``restaurants`` collection with the ``cuisine`` "Pizza". - -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the -corresponding code. - -.. tabs:: - .. tab:: Asynchronous - :tabid: linq-async + :tabid: builders-async .. literalinclude:: ../includes/code-examples/find-many/FindManyAsync.cs - :start-after: start-find-linq-async - :end-before: end-find-linq-async + :start-after: start-find-builders-async + :end-before: end-find-builders-async :language: csharp :copyable: :dedent: @@ -87,6 +62,17 @@ corresponding code. find multiple documents, see `Asynchronous Find Multiple Example <{+example+}/find-many/FindManyAsync.cs>`__. +Find Documents by Using LINQ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The following example uses LINQ to find documents in the +``restaurants`` collection with the ``cuisine`` "Pizza". + +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the +corresponding code. + +.. tabs:: + .. tab:: Synchronous :tabid: linq-sync @@ -101,24 +87,12 @@ corresponding code. find multiple documents, see `Synchronous Find Multiple Example <{+example+}/find-many/FindMany.cs>`__. -.. _csharp_find_all: - -Find All Documents -~~~~~~~~~~~~~~~~~~ - -The following example finds all documents in the ``restaurants`` collection. - -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the -corresponding code. - -.. tabs:: - .. tab:: Asynchronous - :tabid: find-all-async + :tabid: linq-async .. literalinclude:: ../includes/code-examples/find-many/FindManyAsync.cs - :start-after: start-find-all-async - :end-before: end-find-all-async + :start-after: start-find-linq-async + :end-before: end-find-linq-async :language: csharp :copyable: :dedent: @@ -127,6 +101,18 @@ corresponding code. find multiple documents, see `Asynchronous Find Multiple Example <{+example+}/find-many/FindManyAsync.cs>`__. +.. _csharp_find_all: + +Find All Documents +~~~~~~~~~~~~~~~~~~ + +The following example finds all documents in the ``restaurants`` collection. + +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the +corresponding code. + +.. tabs:: + .. tab:: Synchronous :tabid: find-all-sync @@ -141,6 +127,20 @@ corresponding code. find multiple documents, see `Synchronous Find Multiple Example <{+example+}/find-many/FindMany.cs>`__. + .. tab:: Asynchronous + :tabid: find-all-async + + .. literalinclude:: ../includes/code-examples/find-many/FindManyAsync.cs + :start-after: start-find-all-async + :end-before: end-find-all-async + :language: csharp + :copyable: + :dedent: + + For a fully runnable example of using the ``Find()`` method to asynchronously + find multiple documents, see + `Asynchronous Find Multiple Example <{+example+}/find-many/FindManyAsync.cs>`__. + Expected Result ~~~~~~~~~~~~~~~ diff --git a/source/usage-examples/findOne.txt b/source/usage-examples/findOne.txt index 9d65265c..5b4401a7 100644 --- a/source/usage-examples/findOne.txt +++ b/source/usage-examples/findOne.txt @@ -28,15 +28,15 @@ Find a Document by Using Builders The following example uses ``Builders`` to find a document in the ``restaurants`` collection that has a ``name`` field with a value of "Bagels N Buns". -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: builders-async + .. tab:: Synchronous + :tabid: builders-sync - .. literalinclude:: ../includes/code-examples/find-one/FindOneAsync.cs + .. literalinclude:: ../includes/code-examples/find-one/FindOne.cs :start-after: start-find-builders :end-before: end-find-builders :language: csharp @@ -44,12 +44,13 @@ corresponding code. :dedent: For a fully runnable example of using the ``Find()`` method - to asynchronously find one document, see the `Asynchronous Find One Example <{+example+}/find-one/FindOneAsync.cs>`__. + to synchronously find one document, see the `Synchronous Find One Example + <{+example+}/find-one/FindOne.cs>`__. - .. tab:: Synchronous - :tabid: builders-sync + .. tab:: Asynchronous + :tabid: builders-async - .. literalinclude:: ../includes/code-examples/find-one/FindOne.cs + .. literalinclude:: ../includes/code-examples/find-one/FindOneAsync.cs :start-after: start-find-builders :end-before: end-find-builders :language: csharp @@ -57,7 +58,7 @@ corresponding code. :dedent: For a fully runnable example of using the ``Find()`` method - to synchronously find one document, see the `Synchronous Find One Example <{+example+}/find-one/FindOne.cs>`__. + to asynchronously find one document, see the `Asynchronous Find One Example <{+example+}/find-one/FindOneAsync.cs>`__. Find a Document by Using LINQ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -65,15 +66,15 @@ Find a Document by Using LINQ The following example uses LINQ to find a document in the ``restaurants`` collection that has a ``name`` field with a value of "Bagels N Buns". -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: linq-async + .. tab:: Synchronous + :tabid: linq-sync - .. literalinclude:: ../includes/code-examples/find-one/FindOneAsync.cs + .. literalinclude:: ../includes/code-examples/find-one/FindOne.cs :start-after: start-find-linq :end-before: end-find-linq :language: csharp @@ -81,12 +82,13 @@ corresponding code. :dedent: For a fully runnable example of using the ``Find()`` method - to asynchronously find one document, see the `Asynchronous Find One Example <{+example+}/find-one/FindOneAsync.cs>`__. - - .. tab:: Synchronous - :tabid: linq-sync + to synchronously find one document, see the `Synchronous Find One Example + <{+example+}/find-one/FindOne.cs>`__. + + .. tab:: Asynchronous + :tabid: linq-async - .. literalinclude:: ../includes/code-examples/find-one/FindOne.cs + .. literalinclude:: ../includes/code-examples/find-one/FindOneAsync.cs :start-after: start-find-linq :end-before: end-find-linq :language: csharp @@ -94,7 +96,7 @@ corresponding code. :dedent: For a fully runnable example of using the ``Find()`` method - to synchronously find one document, see the `Synchronous Find One Example <{+example+}/find-one/FindOne.cs>`__. + to asynchronously find one document, see the `Asynchronous Find One Example <{+example+}/find-one/FindOneAsync.cs>`__. Expected Result ~~~~~~~~~~~~~~~ diff --git a/source/usage-examples/insertMany.txt b/source/usage-examples/insertMany.txt index 89f631e8..996f5e28 100644 --- a/source/usage-examples/insertMany.txt +++ b/source/usage-examples/insertMany.txt @@ -26,36 +26,36 @@ Example The following example inserts multiple documents into the ``restaurants`` collection. -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: insert-many-async + .. tab:: Synchronous + :tabid: insert-many-sync - .. literalinclude:: ../includes/code-examples/insert-many/InsertManyAsync.cs + .. literalinclude:: ../includes/code-examples/insert-many/InsertMany.cs :start-after: start-insert-many :end-before: end-insert-many :language: csharp :copyable: :dedent: - For a fully runnable example of the ``InsertManyAsync()`` operation, see the - `InsertManyAsync code sample <{+example+}/insert-many/InsertMany.cs>`__. + For a fully runnable example of the ``InsertMany()`` operation, see the + `InsertMany code sample <{+example+}/insert-many/InsertMany.cs>`__. - .. tab:: Synchronous - :tabid: insert-many-sync + .. tab:: Asynchronous + :tabid: insert-many-async - .. literalinclude:: ../includes/code-examples/insert-many/InsertMany.cs + .. literalinclude:: ../includes/code-examples/insert-many/InsertManyAsync.cs :start-after: start-insert-many :end-before: end-insert-many :language: csharp :copyable: :dedent: - For a fully runnable example of the ``InsertMany()`` operation, see the - `InsertMany code sample <{+example+}/insert-many/InsertManyAsync.cs>`__. + For a fully runnable example of the ``InsertManyAsync()`` operation, see the + `InsertManyAsync code sample <{+example+}/insert-many/InsertManyAysnc.cs>`__. Expected Result ~~~~~~~~~~~~~~~ diff --git a/source/usage-examples/insertOne.txt b/source/usage-examples/insertOne.txt index 4ea96a6d..235c8694 100644 --- a/source/usage-examples/insertOne.txt +++ b/source/usage-examples/insertOne.txt @@ -25,24 +25,11 @@ Example The following example inserts a document into the ``restaurants`` collection. -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: insert-one-async - - .. literalinclude:: ../includes/code-examples/insert-one/InsertOneAsync.cs - :start-after: start-insert-one-async - :end-before: end-insert-one-async - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of the ``InsertOneAsync()`` operation, see the - `Asynchronous Insert One Example <{+example+}/insert-one/InsertOneAsync.cs>`__. - .. tab:: Synchronous :tabid: insert-one-sync @@ -56,6 +43,19 @@ corresponding code. For a fully runnable example of the ``InsertOne()`` operation, see the `Synchronous Insert One Example <{+example+}/insert-one/InsertOne.cs>`__. + .. tab:: Asynchronous + :tabid: insert-one-async + + .. literalinclude:: ../includes/code-examples/insert-one/InsertOneAsync.cs + :start-after: start-insert-one-async + :end-before: end-insert-one-async + :language: csharp + :copyable: + :dedent: + + For a fully runnable example of the ``InsertOneAsync()`` operation, see the + `Asynchronous Insert One Example <{+example+}/insert-one/InsertOneAsync.cs>`__. + Expected Result ~~~~~~~~~~~~~~~ @@ -68,7 +68,6 @@ the newly inserted document. The output is similar to the following: Inserting a document... Document Inserted: { "_id" : ObjectId("..."), "name" : "Mongo's Pizza", "restaurant_id" : "12345", "cuisine" : "Pizza", "address" : { "_t" : "MongoDB.Bson.BsonDocument, MongoDB.Bson", "_v" : { "street" : "Pizza St", "zipcode" : "10003" } }, "borough" : "Manhattan", "grades" : [{ "_t" : "MongoDB.Bson.BsonDocument, MongoDB.Bson", "_v" : { } }] } - Additional Information ---------------------- diff --git a/source/usage-examples/replaceOne.txt b/source/usage-examples/replaceOne.txt index e82a9e4b..af2259b4 100644 --- a/source/usage-examples/replaceOne.txt +++ b/source/usage-examples/replaceOne.txt @@ -28,24 +28,11 @@ value of "Pizza" in the ``cuisine`` field. After the replacement, this document have a ``name`` field with a value of "Mongo's Pizza" and new values for the ``address`` and ``borough`` fields. -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: replace-one-async - - .. literalinclude:: ../includes/code-examples/replace-one/ReplaceOneAsync.cs - :start-after: start-replace-one-async - :end-before: end-replace-one-async - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of the ``ReplaceOneAsync()`` operation, see the - `ReplaceOneAsync code sample <{+example+}/replace-one/ReplaceOneAsync.cs>`__. - .. tab:: Synchronous :tabid: replace-one-sync @@ -59,6 +46,19 @@ corresponding code. For a fully runnable example of the ``ReplaceOne()`` operation, see the `ReplaceOne code sample <{+example+}/replace-one/ReplaceOne.cs>`__. + .. tab:: Asynchronous + :tabid: replace-one-async + + .. literalinclude:: ../includes/code-examples/replace-one/ReplaceOneAsync.cs + :start-after: start-replace-one-async + :end-before: end-replace-one-async + :language: csharp + :copyable: + :dedent: + + For a fully runnable example of the ``ReplaceOneAsync()`` operation, see the + `ReplaceOneAsync code sample <{+example+}/replace-one/ReplaceOneAsync.cs>`__. + Expected Result ~~~~~~~~~~~~~~~ diff --git a/source/usage-examples/updateMany.txt b/source/usage-examples/updateMany.txt index 7c1b5203..745ed606 100644 --- a/source/usage-examples/updateMany.txt +++ b/source/usage-examples/updateMany.txt @@ -27,24 +27,11 @@ The following code updates all documents in the ``restaurants`` collection that ``cuisine`` field with the value of "Pizza". After the update, these documents will have a ``cuisine`` field with a value of "Pasta and breadsticks". -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the corresponding +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: update-many-async - - .. literalinclude:: ../includes/code-examples/update-many/UpdateManyAsync.cs - :start-after: start-update-many-async - :end-before: end-update-many-async - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of the ``UpdateManyAsync()`` operation, see the - `UpdateManyAsync code sample <{+example+}/update-many/UpdateManyAsync.cs>`__. - .. tab:: Synchronous :tabid: update-many-sync @@ -58,6 +45,19 @@ code. For a fully runnable example of the ``UpdateMany()`` operation, see the `UpdateMany code sample <{+example+}/update-many/UpdateMany.cs>`__. + .. tab:: Asynchronous + :tabid: update-many-async + + .. literalinclude:: ../includes/code-examples/update-many/UpdateManyAsync.cs + :start-after: start-update-many-async + :end-before: end-update-many-async + :language: csharp + :copyable: + :dedent: + + For a fully runnable example of the ``UpdateManyAsync()`` operation, see the + `UpdateManyAsync code sample <{+example+}/update-many/UpdateManyAsync.cs>`__. + Expected Result ~~~~~~~~~~~~~~~ diff --git a/source/usage-examples/updateOne.txt b/source/usage-examples/updateOne.txt index df6c799a..cf4188b6 100644 --- a/source/usage-examples/updateOne.txt +++ b/source/usage-examples/updateOne.txt @@ -37,37 +37,36 @@ The following example uses ``Builders`` to update the ``name`` of the first document named "Bagels N Buns" in the ``restaurants`` collection to "2 Bagels 2 Buns". -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the +Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code. .. tabs:: - .. tab:: Asynchronous - :tabid: update-async - + .. tab:: Synchronous + :tabid: update-many-sync - .. literalinclude:: ../includes/code-examples/update-one/UpdateOneAsync.cs - :start-after: start-update-one-async - :end-before: end-update-one-async + .. literalinclude:: ../includes/code-examples/update-one/UpdateOne.cs + :start-after: start-update-one + :end-before: end-update-one :language: csharp :copyable: :dedent: For a fully runnable example of the ``UpdateOneAsync()`` operation, see the - `UpdateOneAsync Example <{+example+}/update-one/UpdateOneAsync.cs>`__. + `UpdateOne Example <{+example+}/update-one/UpdateOne.cs>`__. - .. tab:: Synchronous - :tabid: update-many-sync + .. tab:: Asynchronous + :tabid: update-async - .. literalinclude:: ../includes/code-examples/update-one/UpdateOne.cs - :start-after: start-update-one - :end-before: end-update-one + .. literalinclude:: ../includes/code-examples/update-one/UpdateOneAsync.cs + :start-after: start-update-one-async + :end-before: end-update-one-async :language: csharp :copyable: :dedent: For a fully runnable example of the ``UpdateOneAsync()`` operation, see the - `UpdateOne Example <{+example+}/update-one/UpdateOne.cs>`__. + `UpdateOneAsync Example <{+example+}/update-one/UpdateOneAsync.cs>`__. Expected Result ~~~~~~~~~~~~~~~ From 13f2e2291a151fa12b28080336a291d1e2d86172 Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 27 Mar 2025 16:53:24 -0400 Subject: [PATCH 2/2] add back word --- source/fundamentals/crud/read-operations/change-streams.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/fundamentals/crud/read-operations/change-streams.txt b/source/fundamentals/crud/read-operations/change-streams.txt index df8de764..018cbff2 100644 --- a/source/fundamentals/crud/read-operations/change-streams.txt +++ b/source/fundamentals/crud/read-operations/change-streams.txt @@ -66,8 +66,7 @@ classes: The following example opens a change stream on the ``restaurants`` collection and outputs the changes as they occur. Select the :guilabel:`Synchronous` or -:guilabel:`Asynchronous` to see the corresponding -code. +:guilabel:`Asynchronous` tab to see the corresponding code. .. tabs::