<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:56 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-1194] Support for adding Discriminators to a collection Automatically</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1194</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Currently, when using a hierarchy of types (Animal -&amp;gt; Cat, Dog), it is required to always use the base class as the generic type on collection (Animal).&lt;/p&gt;

&lt;p&gt;That&apos;s fine, but if I only want to then work with Cats, I must add the discriminator in manually to every filter. There should be a way to do this automatically.&lt;/p&gt;

&lt;p&gt;------------------------&lt;br/&gt;
There is currently a commit here (&lt;a href=&quot;https://github.com/craiggwilson/mongo-csharp-driver/tree/oftype&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/craiggwilson/mongo-csharp-driver/tree/oftype&lt;/a&gt;) that adds a method called OfType to IMongoCollection&amp;lt;T&amp;gt; which does this exact thing. It includes the discriminator with every filter.&lt;/p&gt;

&lt;p&gt;For instance, `db.GetCollection&amp;lt;Animal&amp;gt;(&quot;animals&quot;).OfType&amp;lt;Cat&amp;gt;();` returns an IFilteredMongoCollection&amp;lt;Cat&amp;gt;, which implements IMongoCollection&amp;lt;Cat&amp;gt;. From here, everything that can be done on a normal collection can be done on this collection, except the discriminator will be added to all filters.&lt;/p&gt;</description>
                <environment></environment>
        <key id="190112">CSHARP-1194</key>
            <summary>Support for adding Discriminators to a collection Automatically</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="craig.wilson@mongodb.com">Craig Wilson</assignee>
                                    <reporter username="craig.wilson@mongodb.com">Craig Wilson</reporter>
                        <labels>
                    </labels>
                <created>Tue, 17 Mar 2015 14:41:53 +0000</created>
                <updated>Wed, 20 Jan 2016 20:09:54 +0000</updated>
                            <resolved>Thu, 3 Sep 2015 16:58:27 +0000</resolved>
                                                    <fixVersion>2.1</fixVersion>
                                                        <votes>4</votes>
                                    <watches>5</watches>
                                                                                                                <comments>
                            <comment id="1021760" author="xgen-internal-githook" created="Thu, 3 Sep 2015 16:55:38 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;rstam&apos;, u&apos;name&apos;: u&apos;rstam&apos;, u&apos;email&apos;: u&apos;robert@robertstam.org&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1194&quot; title=&quot;Support for adding Discriminators to a collection Automatically&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1194&quot;&gt;&lt;del&gt;CSHARP-1194&lt;/del&gt;&lt;/a&gt;: Refactor MongoCollectionImpl OfType method to use new OfType FilterDefinitionBuilder method.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/76209b0c932cfb9cd9777cbdb436d844b62135c9&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/76209b0c932cfb9cd9777cbdb436d844b62135c9&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1021759" author="xgen-internal-githook" created="Thu, 3 Sep 2015 16:55:37 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;rstam&apos;, u&apos;name&apos;: u&apos;rstam&apos;, u&apos;email&apos;: u&apos;robert@robertstam.org&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1194&quot; title=&quot;Support for adding Discriminators to a collection Automatically&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1194&quot;&gt;&lt;del&gt;CSHARP-1194&lt;/del&gt;&lt;/a&gt;: Craig&apos;s further code review changes.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/1e576efd9f648b0d07e762aefdb69390ca2dbde0&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/1e576efd9f648b0d07e762aefdb69390ca2dbde0&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1021758" author="xgen-internal-githook" created="Thu, 3 Sep 2015 16:55:36 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;rstam&apos;, u&apos;name&apos;: u&apos;rstam&apos;, u&apos;email&apos;: u&apos;robert@robertstam.org&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1194&quot; title=&quot;Support for adding Discriminators to a collection Automatically&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1194&quot;&gt;&lt;del&gt;CSHARP-1194&lt;/del&gt;&lt;/a&gt;: Code review changes.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/f0b381e63c4236560ac9240d810bd264fc1dffe6&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/f0b381e63c4236560ac9240d810bd264fc1dffe6&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1021757" author="xgen-internal-githook" created="Thu, 3 Sep 2015 16:55:35 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;craiggwilson&apos;, u&apos;name&apos;: u&apos;Craig Wilson&apos;, u&apos;email&apos;: u&apos;craiggwilson@gmail.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1194&quot; title=&quot;Support for adding Discriminators to a collection Automatically&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1194&quot;&gt;&lt;del&gt;CSHARP-1194&lt;/del&gt;&lt;/a&gt;: added polymorphic support into IMongoCollection&amp;lt;T&amp;gt; using the OfType method.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/32475614f3caadab37410c8f1502497d78d1a803&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/32475614f3caadab37410c8f1502497d78d1a803&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="916012" author="rstam" created="Sat, 16 May 2015 16:56:36 +0000"  >&lt;p&gt;The problem with the approach of creating a filtered collection is that it doesn&apos;t represent at all the reality of what&apos;s in the database.&lt;/p&gt;

&lt;p&gt;Given a variable:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    IMongoCollection&amp;lt;Cat&amp;gt; collection;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;I would expect that it represents a collection that contains Cats. But the database has no such collection. What the database has is a collection of Animals, &lt;b&gt;some&lt;/b&gt; of which might be Cats.&lt;/p&gt;

&lt;p&gt;Furthermore, all operations against such a collection are misleading. For example, given:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    var count = await collection.CountAsync(&quot;{}&quot;);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;I would expect count to be the number of documents stored in the collection. But in the proposed filtered collection implementation that wouldn&apos;t be true, it would actually only return the count of the Cats in the collection (by design of course, but it&apos;s misleading).&lt;/p&gt;

&lt;p&gt;Further examples of confusion can arise in queries. For example, the following Find might not return any documents:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    var list = await collection.Find(&quot;{ Name : &apos;Spots&apos; }&quot;).ToListAsync();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;Even if the collection has plenty of documents with the name &quot;Spots&quot;. It all depends on whether there are any Cats named &quot;Spots&quot;, but that important detail is hidden away in a side effect.&lt;/p&gt;

&lt;p&gt;I think our emphasis should be on making it easier to issue queries against polymorphic collections, not on creating filtered collections that don&apos;t correspond to anything that actually exists in reality.&lt;/p&gt;

&lt;p&gt;It would be far more transparent to simply embrace the notion that certain types of queries imply that the matching documents are of a certain type, and take advantage of that.&lt;/p&gt;

&lt;p&gt;For example, one could write (where OfType would be a new filter builder method):&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    var builder = Builders&amp;lt;Animal&amp;gt;.Filter;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    var list = await collection.Find(builder.OfType&amp;lt;Cat&amp;gt;() &amp;amp; &quot;{ Name : &apos;Spots&apos; }&quot;).ToListAsync();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;In this case, not only is nothing hidden (we immediately see that we are only querying Cats, this is not hidden in some side effect!), but we can take advantage of the type information in the OfType filter to automatically make the result be of type List&amp;lt;Cat&amp;gt; instead of List&amp;lt;Animal&amp;gt;.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hredon:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="549">C# Sprint 20</customfieldvalue>
    <customfieldvalue id="590">C# Sprint 22</customfieldvalue>
    <customfieldvalue id="591">C# Sprint 23</customfieldvalue>
    <customfieldvalue id="624">C# Sprint 24</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>