From 8fe7b8b7c2de57073dcc79575811781e2156fb2e Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Wed, 2 Apr 2025 12:48:15 -0500 Subject: [PATCH] first draft --- .../crud/read-operations/retrieve.txt | 9 +- .../crud/write-operations/delete.txt | 6 +- .../crud/write-operations/insert.txt | 6 +- .../crud/write-operations/replace.txt | 9 + .../crud/write-operations/update-many.txt | 5 +- .../crud/write-operations/update-one.txt | 5 +- .../includes/page-templates/update/update.rst | 4 +- source/usage-examples/deleteMany.txt | 82 -------- source/usage-examples/deleteOne.txt | 91 --------- source/usage-examples/facets.toml | 3 - source/usage-examples/findMany.txt | 178 ------------------ source/usage-examples/findOne.txt | 130 ------------- source/usage-examples/insertMany.txt | 82 -------- source/usage-examples/insertOne.txt | 83 -------- source/usage-examples/replaceOne.txt | 88 --------- source/usage-examples/updateMany.txt | 86 --------- source/usage-examples/updateOne.txt | 98 ---------- 17 files changed, 33 insertions(+), 932 deletions(-) delete mode 100644 source/usage-examples/deleteMany.txt delete mode 100644 source/usage-examples/deleteOne.txt delete mode 100644 source/usage-examples/facets.toml delete mode 100644 source/usage-examples/findMany.txt delete mode 100644 source/usage-examples/findOne.txt delete mode 100644 source/usage-examples/insertMany.txt delete mode 100644 source/usage-examples/insertOne.txt delete mode 100644 source/usage-examples/replaceOne.txt delete mode 100644 source/usage-examples/updateMany.txt delete mode 100644 source/usage-examples/updateOne.txt diff --git a/source/fundamentals/crud/read-operations/retrieve.txt b/source/fundamentals/crud/read-operations/retrieve.txt index 396b0580..4527d807 100644 --- a/source/fundamentals/crud/read-operations/retrieve.txt +++ b/source/fundamentals/crud/read-operations/retrieve.txt @@ -272,8 +272,13 @@ To learn more about query filters, see :ref:`csharp-specify-query`. To learn how to specify queries using LINQ, see :ref:`csharp-linq`. -To view runnable examples of the ``Find()`` method, see the -:ref:`csharp-find-one` page. +For runnable examples of the find operations, see the following usage +examples: + +- `FindOne() <{+example+}/find-one/FindOne.cs>`__ +- `FindOneAsync() <{+example+}/find-one/FindOneAsync.cs>`__ +- `FindMany() <{+example+}/find-many/FindMany.cs>`__ +- `FindManyAsync() <{+example+}/find-many/FindManyAsync.cs>`__ API Documentation ~~~~~~~~~~~~~~~~~ diff --git a/source/fundamentals/crud/write-operations/delete.txt b/source/fundamentals/crud/write-operations/delete.txt index 0b5605fe..8b91da80 100644 --- a/source/fundamentals/crud/write-operations/delete.txt +++ b/source/fundamentals/crud/write-operations/delete.txt @@ -214,8 +214,10 @@ Additional Information For runnable examples of the delete operations, see the following usage examples: -- :ref:`csharp-delete-one` -- :ref:`csharp-delete-many` +- `DeleteOne() <{+example+}/delete-one/DeleteOne.cs>`__ +- `DeleteOneAsync() <{+example+}/delete-one/DeleteOneAsync.cs>`__ +- `DeleteMany() <{+example+}/delete-many/DeleteMany.cs>`__ +- `DeleteManyAsync() <{+example+}/delete-many/DeleteManyAsync.cs>`__ API Documentation ~~~~~~~~~~~~~~~~~ diff --git a/source/fundamentals/crud/write-operations/insert.txt b/source/fundamentals/crud/write-operations/insert.txt index 3ead0ef9..e7f3e53f 100644 --- a/source/fundamentals/crud/write-operations/insert.txt +++ b/source/fundamentals/crud/write-operations/insert.txt @@ -281,8 +281,10 @@ Additional Information For runnable examples of the insert operations, see the following usage examples: -- :ref:`csharp-insert-one` -- :ref:`csharp-insert-many` +- `InsertOne() <{+example+}/insert-one/InsertOne.cs>`__ +- `InsertOneAsync() <{+example+}/insert-one/InsertOneAsync.cs>`__ +- `InsertMany() <{+example+}/insert-many/InsertMany.cs>`__ +- `InsertManyAsync() <{+example+}/insert-many/InsertManyAsync.cs>`__ .. To learn more about performing the operations mentioned, see the .. following guides: diff --git a/source/fundamentals/crud/write-operations/replace.txt b/source/fundamentals/crud/write-operations/replace.txt index e64af0d9..c094116b 100644 --- a/source/fundamentals/crud/write-operations/replace.txt +++ b/source/fundamentals/crud/write-operations/replace.txt @@ -241,6 +241,15 @@ The ``ReplaceOneResult`` class contains the following properties: **Data Type:** `BsonValue <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.BsonValue.html>`__ +Additional Information +---------------------- + +For runnable examples of the replace operation, see the following usage +examples: + +- `ReplaceOne() <{+example+}/replace-one/ReplaceOne.cs>`__ +- `ReplaceOneAsync() <{+example+}/replace-one/ReplaceOneAsync.cs>`__ + API Documentation ~~~~~~~~~~~~~~~~~ diff --git a/source/fundamentals/crud/write-operations/update-many.txt b/source/fundamentals/crud/write-operations/update-many.txt index e05203fd..7d46dfce 100644 --- a/source/fundamentals/crud/write-operations/update-many.txt +++ b/source/fundamentals/crud/write-operations/update-many.txt @@ -49,9 +49,10 @@ Update Many multiple documents - .. replacement:: usage-examples-link + .. replacement:: usage-examples-links - :ref:`csharp-examples-update-many` + - `UpdateMany() <{+example+}/update-many/UpdateMany.cs>`__ + - `UpdateManyAsync() <{+example+}/update-many/UpdateManyAsync.cs>`__ .. replacement:: sync-api-link diff --git a/source/fundamentals/crud/write-operations/update-one.txt b/source/fundamentals/crud/write-operations/update-one.txt index 192bf0ed..9afb9fd3 100644 --- a/source/fundamentals/crud/write-operations/update-one.txt +++ b/source/fundamentals/crud/write-operations/update-one.txt @@ -49,9 +49,10 @@ Update One a single document - .. replacement:: usage-examples-link + .. replacement:: usage-examples-links - :ref:`csharp-examples-update-one` + - `UpdateOne() <{+example+}/update-one/UpdateOne.cs>`__ + - `UpdateOneAsync() <{+example+}/update-one/UpdateOneAsync.cs>`__ .. replacement:: sync-api-link diff --git a/source/includes/page-templates/update/update.rst b/source/includes/page-templates/update/update.rst index 49741885..c6087ced 100644 --- a/source/includes/page-templates/update/update.rst +++ b/source/includes/page-templates/update/update.rst @@ -246,7 +246,9 @@ Additional Information |instruqt-lab-instructions| -For runnable examples of the update operations, see the |usage-examples-link| page. +For runnable examples of the update operations, see the following usage examples: + +|usage-examples-links| To learn more about creating query filters, see the :ref:`csharp-specify-query` guide. diff --git a/source/usage-examples/deleteMany.txt b/source/usage-examples/deleteMany.txt deleted file mode 100644 index 96103487..00000000 --- a/source/usage-examples/deleteMany.txt +++ /dev/null @@ -1,82 +0,0 @@ -.. _csharp-delete-many: - -===================== -Delete Many Documents -===================== - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: code example, .NET, operation - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -You can delete more than one document using the ``DeleteMany()`` synchronous -method or the ``DeleteManyAsync()`` asynchronous method on a collection object. - -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 -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 - - .. literalinclude:: ../includes/code-examples/delete-many/DeleteMany.cs - :start-after: start-delete-many-builders - :end-before: end-delete-many-builders - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of the ``DeleteMany()`` operation, see the - `DeleteMany code sample <{+example+}/delete-many/DeleteMany.cs>`__. - -Expected Result -~~~~~~~~~~~~~~~ - -Running either of the preceding full examples prints the following results: - -.. code-block:: none - - Deleting documents... - Deleted documents: 6086 - Resetting sample data...done. - -Additional Information ----------------------- - -To learn more about deleting documents, see the :ref:`csharp-delete-guide` guide. - -To learn more about using builders, see :ref:`csharp-builders`. - -API Documentation ------------------ - -* `DeleteMany() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.DeleteMany.html>`__ -* `DeleteManyAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.DeleteManyAsync.html>`__ diff --git a/source/usage-examples/deleteOne.txt b/source/usage-examples/deleteOne.txt deleted file mode 100644 index edd66963..00000000 --- a/source/usage-examples/deleteOne.txt +++ /dev/null @@ -1,91 +0,0 @@ -.. _csharp-delete-one: - -================= -Delete a Document -================= - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: code example, .NET, operation - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -You can delete a document from a collection by using the synchronous -``DeleteOne()`` method, or the asynchronous ``DeleteOneAsync()`` method. - -.. note:: - - The ``DeleteOne()`` method deletes only the first document that matches the filter. - To delete more than one document, use the ``DeleteMany()`` method. - - To learn more about using ``DeleteMany()``, see :ref:`csharp-delete-many`. - -Example -------- - -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 -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 - - .. literalinclude:: ../includes/code-examples/delete-one/DeleteOne.cs - :start-after: start-delete-one-builders - :end-before: end-delete-one-builders - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of the ``DeleteOne()`` method, see the - `Synchronous Delete One Example <{+example+}/delete-one/DeleteOne.cs>`__ - -Expected Result -~~~~~~~~~~~~~~~ - -Running either of the preceding full examples prints the following results: - -.. code-block:: none - - Deleting a document with builders... - Deleted documents: 1 - -Additional Information ----------------------- - -To learn more about deleting documents, see the :ref:`csharp-delete-guide` guide. - -To learn more about using builders, see :ref:`csharp-builders`. - -API Documentation ------------------ - -- `DeleteOne() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.DeleteOne.html>`__ -- `DeleteOneAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.DeleteOneAsync.html>`__ \ No newline at end of file diff --git a/source/usage-examples/facets.toml b/source/usage-examples/facets.toml deleted file mode 100644 index 07bd7b7f..00000000 --- a/source/usage-examples/facets.toml +++ /dev/null @@ -1,3 +0,0 @@ -[[facets]] -category = "genre" -value = "tutorial" diff --git a/source/usage-examples/findMany.txt b/source/usage-examples/findMany.txt deleted file mode 100644 index 81cb98f6..00000000 --- a/source/usage-examples/findMany.txt +++ /dev/null @@ -1,178 +0,0 @@ -.. _csharp-find-multiple: - -======================= -Find Multiple Documents -======================= - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: code example, .NET, operation - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -You can retrieve multiple documents from a collection by using the -``Find()`` method. - -Example -------- - -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 -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 - - .. literalinclude:: ../includes/code-examples/find-many/FindMany.cs - :start-after: start-find-builders-sync - :end-before: end-find-builders-sync - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of using the ``Find()`` method to synchronously - 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 - - .. literalinclude:: ../includes/code-examples/find-many/FindManyAsync.cs - :start-after: start-find-linq-async - :end-before: end-find-linq-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: linq-sync - - .. literalinclude:: ../includes/code-examples/find-many/FindMany.cs - :start-after: start-find-linq-sync - :end-before: end-find-linq-sync - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of using the ``Find()`` method to synchronously - 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 - - .. 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>`__. - - .. tab:: Synchronous - :tabid: find-all-sync - - .. literalinclude:: ../includes/code-examples/find-many/FindMany.cs - :start-after: start-find-all-sync - :end-before: end-find-all-sync - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of using the ``Find()`` method to synchronously - find multiple documents, see - `Synchronous Find Multiple Example <{+example+}/find-many/FindMany.cs>`__. - -Expected Result -~~~~~~~~~~~~~~~ - -Running the preceding full examples prints the following results: - -.. code-block:: none - - Finding documents with builders...: - Number of documents found: 1163 - - Finding documents with LINQ...: - Number of documents found: 1163 - - Finding all documents...: - Number of documents found: 25359 - -.. tip:: Sample Datasets - - These examples use the :atlas:`sample datasets ` provided by Atlas. - The number of documents returned may differ depending on the data in your - collection. - -Additional Information ----------------------- - -To learn more about retrieving documents, see the :ref:`csharp-retrieve` guide. - -To learn more about using builders, see :ref:`csharp-builders`. - -To learn how to find documents using LINQ, see :ref:`csharp-linq`. - -API Documentation ------------------ - -- `Find() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollectionExtensions.Find.html>`__ \ No newline at end of file diff --git a/source/usage-examples/findOne.txt b/source/usage-examples/findOne.txt deleted file mode 100644 index 9d65265c..00000000 --- a/source/usage-examples/findOne.txt +++ /dev/null @@ -1,130 +0,0 @@ -.. _csharp-find-one: - -=============== -Find a Document -=============== - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: code example, .NET, operation - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -You can retrieve a document by using the ``Find()`` method on a collection object. - -Example -------- - -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 -corresponding code. - -.. tabs:: - - .. tab:: Asynchronous - :tabid: builders-async - - .. literalinclude:: ../includes/code-examples/find-one/FindOneAsync.cs - :start-after: start-find-builders - :end-before: end-find-builders - :language: csharp - :copyable: - :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: builders-sync - - .. literalinclude:: ../includes/code-examples/find-one/FindOne.cs - :start-after: start-find-builders - :end-before: end-find-builders - :language: csharp - :copyable: - :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>`__. - -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 -corresponding code. - -.. tabs:: - - .. tab:: Asynchronous - :tabid: linq-async - - .. literalinclude:: ../includes/code-examples/find-one/FindOneAsync.cs - :start-after: start-find-linq - :end-before: end-find-linq - :language: csharp - :copyable: - :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 - - .. literalinclude:: ../includes/code-examples/find-one/FindOne.cs - :start-after: start-find-linq - :end-before: end-find-linq - :language: csharp - :copyable: - :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>`__. - -Expected Result -~~~~~~~~~~~~~~~ - -Running any of the preceding full examples prints results similar to the following: - -.. code-block:: none - - { - "_id" : ObjectId("5eb3d668b31de5d588f42950"), - "name" : "Bagels N Buns", - "restaurant_id" : "40363427", - "cuisine" : "Delicatessen", - "address" : {...}, - "borough" : "Staten Island", - "grades" : [...] - } - -Additional Information ----------------------- - -To learn more about retrieving documents, see the :ref:`csharp-retrieve` guide. - -To learn more about using builders, see :ref:`csharp-builders`. - -To learn how to find a document using LINQ, see :ref:`csharp-linq`. - -API Documentation ------------------ - -- `Find() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollectionExtensions.Find.html>`__ -- `FirstOrDefault() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IFindFluentExtensions.FirstOrDefault.html>`__ -- `FirstOrDefaultAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Linq.MongoQueryable.FirstOrDefaultAsync.html>`__ diff --git a/source/usage-examples/insertMany.txt b/source/usage-examples/insertMany.txt deleted file mode 100644 index 89f631e8..00000000 --- a/source/usage-examples/insertMany.txt +++ /dev/null @@ -1,82 +0,0 @@ -.. _csharp-insert-many: - -========================= -Insert Multiple Documents -========================= - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: code example, .NET, operation - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -You can insert multiple documents into a collection by using the synchronous -``InsertMany()`` method or the asynchronous ``InsertManyAsync()`` method. - -Example -------- - -The following example inserts multiple documents into -the ``restaurants`` collection. - -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the -corresponding code. - -.. tabs:: - - .. tab:: Asynchronous - :tabid: insert-many-async - - .. 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 ``InsertManyAsync()`` operation, see the - `InsertManyAsync code sample <{+example+}/insert-many/InsertMany.cs>`__. - - .. tab:: Synchronous - :tabid: insert-many-sync - - .. 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 ``InsertMany()`` operation, see the - `InsertMany code sample <{+example+}/insert-many/InsertManyAsync.cs>`__. - -Expected Result -~~~~~~~~~~~~~~~ - -After running either of the preceding full examples, the output is as follows: - -.. code-block:: none - - Number of restaurants found before insert: 0 - - Inserting documents... - Number of restaurants inserted: 5 - - -Additional Information ----------------------- - -To learn more about using builders, see :ref:`csharp-builders`. - -API Documentation ------------------ - -- `InsertMany() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.InsertMany.html>`__ -- `InsertManyAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.InsertManyAsync.html>`__ diff --git a/source/usage-examples/insertOne.txt b/source/usage-examples/insertOne.txt deleted file mode 100644 index 4ea96a6d..00000000 --- a/source/usage-examples/insertOne.txt +++ /dev/null @@ -1,83 +0,0 @@ -.. _csharp-insert-one: - -================= -Insert a Document -================= - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: code example, .NET, operation - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -You can insert a single document into a collection by using the synchronous -``InsertOne()`` method, or the asynchronous ``InsertOneAsync()`` method. - -Example -------- - -The following example inserts a document into the ``restaurants`` collection. - -Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` 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 - - .. literalinclude:: ../includes/code-examples/insert-one/InsertOne.cs - :start-after: start-insert-one - :end-before: end-insert-one - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of the ``InsertOne()`` operation, see the - `Synchronous Insert One Example <{+example+}/insert-one/InsertOne.cs>`__. - -Expected Result -~~~~~~~~~~~~~~~ - -After running either of the preceding full examples, the ``InsertOne()`` -method inserts the document, and the :ref:`Find() ` method returns -the newly inserted document. The output is similar to the following: - -.. code-block:: none - - 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 ----------------------- - -To learn more about using builders, see :ref:`csharp-builders`. - -API Documentation ------------------ - -- `InsertOne() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.InsertMany.html>`__ -- `InsertOneAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.InsertOneAsync.html>`__ -- `Find() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollectionExtensions.Find.html>`__ -- `FirstOrDefault() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IFindFluentExtensions.FirstOrDefault.html>`__ diff --git a/source/usage-examples/replaceOne.txt b/source/usage-examples/replaceOne.txt deleted file mode 100644 index e82a9e4b..00000000 --- a/source/usage-examples/replaceOne.txt +++ /dev/null @@ -1,88 +0,0 @@ -.. _csharp-replace-one: - -================== -Replace a Document -================== - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: code example, .NET, operation - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -You can replace one document with another by using the ``ReplaceOne()`` synchronous method -or the ``ReplaceOneAsync()`` asynchronous method on a collection object. - -Example -------- - -The following code replaces the first document in the ``restaurants`` collection that has a -value of "Pizza" in the ``cuisine`` field. After the replacement, this document will -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 -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 - - .. literalinclude:: ../includes/code-examples/replace-one/ReplaceOne.cs - :start-after: start-replace-one - :end-before: end-replace-one - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of the ``ReplaceOne()`` operation, see the - `ReplaceOne code sample <{+example+}/replace-one/ReplaceOne.cs>`__. - -Expected Result -~~~~~~~~~~~~~~~ - -Running either of the preceding full examples prints the following results: - -.. code-block:: none - - First pizza restaurant before replacement: J&V Famous Pizza - Restaurants modified by replacement: 1 - First pizza restaurant after replacement: Mongo's Pizza - Resetting sample data...done. - -Additional Information ----------------------- - -To learn more about replacing documents, see the :ref:`csharp-replace-operation` -guide. - -To learn more about using builders, see :ref:`csharp-builders`. - -API Documentation ------------------ - -* `ReplaceOne() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.ReplaceOne.html>`__ -* `ReplaceOneAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.ReplaceOneAsync.html>`__ -* `ReplaceOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ReplaceOptions.html>`__ -* `ReplaceOneResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ReplaceOneResult.html>`__ \ No newline at end of file diff --git a/source/usage-examples/updateMany.txt b/source/usage-examples/updateMany.txt deleted file mode 100644 index 7c1b5203..00000000 --- a/source/usage-examples/updateMany.txt +++ /dev/null @@ -1,86 +0,0 @@ -.. _csharp-examples-update-many: - -===================== -Update Many Documents -===================== - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: code example, .NET, operation - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -You can update more than one document using the ``UpdateMany()`` method on -a collection object. - -Example -------- - -The following code updates all documents in the ``restaurants`` collection that have a -``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 -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 - - .. literalinclude:: ../includes/code-examples/update-many/UpdateMany.cs - :start-after: start-update-many - :end-before: end-update-many - :language: csharp - :copyable: - :dedent: - - For a fully runnable example of the ``UpdateMany()`` operation, see the - `UpdateMany code sample <{+example+}/update-many/UpdateMany.cs>`__. - -Expected Result -~~~~~~~~~~~~~~~ - -Running either of the preceding full examples prints the following results: - -.. code-block:: none - - Restaurants with cuisine "Pizza" found: 1163 - Restaurants modified by update: 1163 - Restaurants with cuisine "Pasta and breadsticks" found after update: 1163 - Resetting sample data...done. - -More Information ----------------- - -To learn more about updating documents, see the :ref:`csharp-update-many` guide. - -To learn more about using builders, see :ref:`csharp-builders`. - -API Documentation ------------------ - -* `UpdateMany() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.UpdateMany.html>`__ -* `UpdateManyAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.UpdateManyAsync.html>`__ -* `UpdateOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateOptions.html>`__ -* `UpdateResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateResult.html>`__ \ No newline at end of file diff --git a/source/usage-examples/updateOne.txt b/source/usage-examples/updateOne.txt deleted file mode 100644 index df6c799a..00000000 --- a/source/usage-examples/updateOne.txt +++ /dev/null @@ -1,98 +0,0 @@ -.. _csharp-examples-update-one: - -================= -Update a Document -================= - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: code example, .NET, operation - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -You can update a single document using the `UpdateOne() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.UpdateOne.html>`__ method on -a ``MongoCollection`` object. This method requires a **query filter**, which specifies which document to update, and an **update** statement, which specifies the changes the driver should make to the first document matching the query filter. - -.. note:: - - The ``UpdateOne()`` method updates only the first document that matches the - filter. To update more than one document, use the :ref:`UpdateMany() method `. - -.. tip:: - - You can pass an instance of `UpdateOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateOptions.html>`__ to the ``UpdateOne()`` method in - order to customize its behavior. - -Example -------- - -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 -corresponding code. - -.. tabs:: - - .. tab:: Asynchronous - :tabid: update-async - - - .. 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 - `UpdateOneAsync Example <{+example+}/update-one/UpdateOneAsync.cs>`__. - - .. tab:: Synchronous - :tabid: update-many-sync - - .. 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 - `UpdateOne Example <{+example+}/update-one/UpdateOne.cs>`__. - -Expected Result -~~~~~~~~~~~~~~~ - -After running either of the preceding full examples, each call to ``UpdateOne()`` -writes the following to the console: - -.. code-block:: none - - Updated documents: 1 - -.. tip:: - - ``UpdateOne()`` returns an `UpdateResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateResult.html>`__ object. - -More Information ----------------- - -To learn more about updating documents, see the :ref:`csharp-update-one` guide. - -To learn more about using builders, see :ref:`csharp-builders`. - -API Documentation ------------------ - -* `UpdateOne() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.UpdateOne.html>`__ -* `UpdateOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateOptions.html>`__ -* `UpdateResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateResult.html>`__ \ No newline at end of file