Skip to content

Commit

Permalink
docsp-27681 - move example classes (#150)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9ec1bae)
  • Loading branch information
mongoKart committed Dec 20, 2023
1 parent 3093905 commit dbdbbf9
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 213 deletions.
31 changes: 31 additions & 0 deletions source/usage-examples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
Usage Examples
==============

.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code, .NET, operation

.. contents:: On this page
:local:
:backlinks: none
Expand Down Expand Up @@ -60,3 +67,27 @@ your MongoDB instance:

For more information about connecting to your MongoDB instance, see the
:ref:`Connection Guide <csharp-connection>`.

Example Classes
---------------

The usage examples in this section show how to perform operations on documents
in the ``restaurants`` collection. The examples use the following ``Restaurant``,
``Address``, and ``GradeEntry`` classes to model the data in this collection:

.. literalinclude:: /includes/code-examples/Restaurant.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/Address.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/GradeEntry.cs
:language: csharp
:copyable:
:dedent:

.. include:: /includes/convention-pack-note.rst
27 changes: 6 additions & 21 deletions source/usage-examples/deleteMany.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
Delete Many Documents
=====================

.. default-domain:: mongodb
.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code example, .NET, operation

.. contents:: On this page
:local:
Expand All @@ -18,26 +23,6 @@ method or the ``DeleteManyAsync()`` asynchronous method on a collection object.
Example
-------

The examples on this page use the following ``Restaurant``, ``Address``, and ``GradeEntry``
classes as models:

.. literalinclude:: /includes/code-examples/Restaurant.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/Address.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/GradeEntry.cs
:language: csharp
:copyable:
:dedent:

.. include:: /includes/convention-pack-note.rst

The following code deletes all documents in the ``restaurants`` collection whose
``borough`` field value equals the word "Brooklyn".

Expand Down
35 changes: 10 additions & 25 deletions source/usage-examples/deleteOne.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
Delete a Document
=================

.. default-domain:: mongodb
.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code example, .NET, operation

.. contents:: On this page
:local:
Expand All @@ -22,31 +27,11 @@ You can delete a document from a collection by using the synchronous

To learn more about using ``DeleteMany()``, see :ref:`csharp-delete-many`.

Examples
--------

The examples on this page use the following ``Restaurant``, ``Address``, and ``GradeEntry``
classes as models:

.. literalinclude:: /includes/code-examples/Restaurant.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/Address.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/GradeEntry.cs
:language: csharp
:copyable:
:dedent:

.. include:: /includes/convention-pack-note.rst
Example
-------

Delete a Document Using Builders
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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".
Expand Down
39 changes: 12 additions & 27 deletions source/usage-examples/findMany.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
Find Multiple Documents
=======================

.. default-domain:: mongodb
.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code example, .NET, operation

.. contents:: On this page
:local:
Expand All @@ -15,31 +20,11 @@ Find Multiple Documents
You can retrieve multiple documents from a collection by using the
``Find()`` method.

Examples
--------

The examples on this page use the following ``Restaurant``, ``Address``, and ``GradeEntry``
classes as models:

.. literalinclude:: /includes/code-examples/Restaurant.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/Address.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/GradeEntry.cs
:language: csharp
:copyable:
:dedent:

.. include:: /includes/convention-pack-note.rst
Example
-------

Find Documents Using Builders
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Find Documents by Using Builders
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following example uses ``Builders`` to find documents in
the ``restaurants`` collection with the ``cuisine`` "Pizza".
Expand Down Expand Up @@ -77,8 +62,8 @@ corresponding code.
find multiple documents, see
`Synchronous Find Multiple Example <{+example+}/find-many/FindMany.cs>`__.

Find Documents Using LINQ
~~~~~~~~~~~~~~~~~~~~~~~~~
Find Documents by Using LINQ
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following example uses LINQ to find documents in the
``restaurants`` collection with the ``cuisine`` "Pizza".
Expand Down
39 changes: 12 additions & 27 deletions source/usage-examples/findOne.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
Find a Document
===============

.. default-domain:: mongodb
.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code example, .NET, operation

.. contents:: On this page
:local:
Expand All @@ -14,31 +19,11 @@ Find a Document

You can retrieve a document by using the ``Find()`` method on a collection object.

Examples
--------

The examples on this page use the following ``Restaurant``, ``Address``, and ``GradeEntry``
classes as models:

.. literalinclude:: /includes/code-examples/Restaurant.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/Address.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/GradeEntry.cs
:language: csharp
:copyable:
:dedent:

.. include:: /includes/convention-pack-note.rst
Example
-------

Find a Document Using Builders
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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".
Expand Down Expand Up @@ -74,8 +59,8 @@ corresponding code.
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 Using LINQ
~~~~~~~~~~~~~~~~~~~~~~~~~~
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".
Expand Down
31 changes: 8 additions & 23 deletions source/usage-examples/insertMany.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
Insert Multiple Documents
=========================

.. default-domain:: mongodb
.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code example, .NET, operation

.. contents:: On this page
:local:
Expand All @@ -15,29 +20,9 @@ Insert Multiple Documents
You can insert multiple documents into a collection by using the synchronous
``InsertMany()`` method or the asynchronous ``InsertManyAsync()`` method.

Examples
--------

The examples on this page use the following ``Restaurant``, ``Address``, and ``GradeEntry``
classes as models:

.. literalinclude:: /includes/code-examples/Restaurant.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/Address.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/GradeEntry.cs
:language: csharp
:copyable:
:dedent:
Example
-------

.. include:: /includes/convention-pack-note.rst

The following example inserts multiple documents into
the ``restaurants`` collection.

Expand Down
34 changes: 9 additions & 25 deletions source/usage-examples/insertOne.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
Insert a Document
=================

.. default-domain:: mongodb
.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code example, .NET, operation

.. contents:: On this page
:local:
Expand All @@ -15,31 +20,10 @@ Insert a Document
You can insert a single document into a collection by using the synchronous
``InsertOne()`` method, or the asynchronous ``InsertOneAsync()`` method.

Examples
--------
Example
-------

The examples on this page use the following ``Restaurant``, ``Address``, and ``GradeEntry``
classes as models:

.. literalinclude:: /includes/code-examples/Restaurant.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/Address.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/GradeEntry.cs
:language: csharp
:copyable:
:dedent:

.. include:: /includes/convention-pack-note.rst

The following example inserts a document into
the ``restaurants`` collection.
The following example inserts a document into the ``restaurants`` collection.

Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the
corresponding code.
Expand Down
27 changes: 6 additions & 21 deletions source/usage-examples/replaceOne.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
Replace a Document
==================

.. default-domain:: mongodb
.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code example, .NET, operation

.. contents:: On this page
:local:
Expand All @@ -18,26 +23,6 @@ or the ``ReplaceOneAsync()`` asynchronous method on a collection object.
Example
-------

The examples on this page use the following ``Restaurant``, ``Address``, and ``GradeEntry``
classes as models:

.. literalinclude:: /includes/code-examples/Restaurant.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/Address.cs
:language: csharp
:copyable:
:dedent:

.. literalinclude:: /includes/code-examples/GradeEntry.cs
:language: csharp
:copyable:
:dedent:

.. include:: /includes/convention-pack-note.rst

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
Expand Down
Loading

0 comments on commit dbdbbf9

Please sign in to comment.