From 31706959f6987cfdd412bbe99601af1964384c67 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:39:01 -0600 Subject: [PATCH 1/4] wip --- .../serialization/polymorphic-objects.txt | 14 ++++++++- source/upgrade/v3.txt | 29 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/source/fundamentals/serialization/polymorphic-objects.txt b/source/fundamentals/serialization/polymorphic-objects.txt index 0a921f01..07a4dc92 100644 --- a/source/fundamentals/serialization/polymorphic-objects.txt +++ b/source/fundamentals/serialization/polymorphic-objects.txt @@ -156,7 +156,19 @@ you must explicitly list each class you're looking for: .. code-block:: csharp :copyable: true - var query = coll.Aggregate().Match(a => a is Cat || a is Lion || a is Tiger); + var query = coll.AsQueryable().Where( + item => item.GetType() == typeof(Cat) || + item.GetType() == typeof(Lion) || + item.GetType() == typeof(Tiger)); + +.. note:: OfType() and the is Operator + + When checking the type of a scalar discriminator, use the ``Where`` syntax shown in + the preceding code example. If you try to use the ``Aggregate().OfType()`` method, + or if you pass an expression containing the ``is`` operator to the + ``Aggregate().Match()`` method, the driver throws an exception. + +.. _csharp-discriminator-hierarchical: HierarchicalDiscriminatorConvention ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/source/upgrade/v3.txt b/source/upgrade/v3.txt index 0cd51180..edda35f1 100644 --- a/source/upgrade/v3.txt +++ b/source/upgrade/v3.txt @@ -203,4 +203,31 @@ Version 3.0 Breaking Changes property instead. - The driver removes individual cluster events from ``MongoClient.Cluster``. To listen for - cluster events, use `ClusterBuilder.Subscribe() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Core.Configuration.ClusterBuilder.Subscribe.html>`__. \ No newline at end of file + cluster events, call the `ClusterBuilder.Subscribe() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Core.Configuration.ClusterBuilder.Subscribe.html>`__ + method. + +- If any type in a collection uses a scalar discriminator, the driver throws + an exception if you perform either of the following actions on the collection: + + - Call the ``Aggregate().OfType()`` method, as in the following example: + + .. code-block:: csharp + + collection.Aggregate().OfType() + + - Call the ``Aggregate().Match(item => item is T)`` method, as in the following example: + + .. code-block:: csharp + + collection.Aggregate().Match(item => item is T) + + To use either of the preceding methods on a collection, you can apply a hierarchical + discriminator to each class in the collection. See + the :ref:`Polymorphic Objects ` + page to learn how to do so. + + Alternatively, you can check each item's type in a different way. For example, you + can call the item's ``GetType()`` method and compare the result to the type you're + looking for, as shown here: ``item.GetType() == typeof(T)`` + + To learn more about type discriminators, see :ref:``. \ No newline at end of file From 5b54403435bdabfa9cbed9c72a6cbc28751ff766 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:43:13 -0600 Subject: [PATCH 2/4] remove 2.21 --- source/whats-new.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/whats-new.txt b/source/whats-new.txt index a6ccfef9..0ffa607a 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -15,7 +15,7 @@ What's New :values: reference .. meta:: - :keywords: update, new feature, deprecation, upgrade, driver v2.19, driver v2.20, driver v2.21, driver v2.22, driver v2.23, driver v2.24, driver v2.25, driver v2.26, driver v2.27, driver v2.28, driver v3.0 + :keywords: update, new feature, deprecation, upgrade, driver v2.22, driver v2.23, driver v2.24, driver v2.25, driver v2.26, driver v2.27, driver v2.28, driver v3.0 Learn what's new in: @@ -29,7 +29,6 @@ Learn what's new in: * :ref:`Version 2.24 ` * :ref:`Version 2.23 ` * :ref:`Version 2.22 ` -* :ref:`Version 2.21 ` .. _upcoming-breaking-changes: From 4a0f22abb1362a16ce34d74af0ea6cb00ceb2ed6 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:46:56 -0600 Subject: [PATCH 3/4] update code --- source/upgrade/v3.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/upgrade/v3.txt b/source/upgrade/v3.txt index edda35f1..53d3283d 100644 --- a/source/upgrade/v3.txt +++ b/source/upgrade/v3.txt @@ -227,7 +227,11 @@ Version 3.0 Breaking Changes page to learn how to do so. Alternatively, you can check each item's type in a different way. For example, you - can call the item's ``GetType()`` method and compare the result to the type you're - looking for, as shown here: ``item.GetType() == typeof(T)`` + can call the ``Where()`` method and pass an expression that compares the item's type + to the type you're looking for, as in the following example: + + .. code-block:: csharp + + collection.AsQueryable().Where(item => item.GetType() == typeof(T)); To learn more about type discriminators, see :ref:``. \ No newline at end of file From b4b242bbb0631cd9592003d8b3b1f7c8655d9ec0 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:08:23 -0600 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Stephanie <52582720+stephmarie17@users.noreply.github.com> --- source/upgrade/v3.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/upgrade/v3.txt b/source/upgrade/v3.txt index 53d3283d..63c9686c 100644 --- a/source/upgrade/v3.txt +++ b/source/upgrade/v3.txt @@ -224,7 +224,7 @@ Version 3.0 Breaking Changes To use either of the preceding methods on a collection, you can apply a hierarchical discriminator to each class in the collection. See the :ref:`Polymorphic Objects ` - page to learn how to do so. + page to learn how. Alternatively, you can check each item's type in a different way. For example, you can call the ``Where()`` method and pass an expression that compares the item's type